Calling API methods from an external android app


I am in the process of developing an android app and my app has to create a stock entry in the Stock Entry table(which has links to other tables like Stock Entry detail etc) for a read bar code (which is got from a scanner app on my android device) and is equivalent a Serial no in ERPNext .

Now I am unable to use a simple POST request Restful API like this(as per documentation)

POST http://frappe.local:8000/api/resource/Stock Entry

Since this was a bit complicated, I thought I’ll write an API method and then call that method using GET from my android app while passing the read bar code/serial number as a parameter.

To write this custom API method, I followed these steps

  1. frappe-bench$ bench get-app renfield

2)frappe-bench$ bench –site inventory install-app renfield

  1. frappe-bench$ bench –site inventory migrate

So now, I created an file in this folder

Now in the file I have this white listed method that takes a serial_no string and creates a stock entry and all other entries.
def make_stock_entry(serial_no):
###code here to update stock entry and related tables

before testing it on Android, I used Postman to check if the method call works, so I did this

All that I get a error message saying Invalid Method

What am I doing wrong and where should I put my white listed method so that I can make a RPC call like?
GET http://server:8000/api/method/{name_of_method with arguments}

Please note I am successfully able to query the table, list the entries etc with the ReST APIs


1 Like

My guess is that there’s a syntax bug in your python code. You’ll get an Invalid Method error if there is.

You might want to try a very basic method to start. Something like:

def make_stock_entry():
return ‘test’

That way you can isolate whether or not it’s a bug in your code or the way you’re calling it.

Hi Ben,

Thank you for your response. I tried what you suggested and I realized I couldn’t call my method from inside my custom script in erpnext either. After diagnosing the issue, I figured I had not installed my custom app properly on my site and there was some migration error. So once I installed the app correctly, the method call seemed to work perfectly.

Thanks again for your input. Problem solved.