Calling API methods from an external android app

Hello,

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 https://github.com/umaepoch/renfield

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

  1. frappe-bench$ bench –site inventory migrate

So now, I created an api.py file in this folder
frappe-bench/apps/renfield/renfield/api.py

Now in the api.py file I have this white listed method that takes a serial_no string and creates a stock entry and all other entries.
@frappe.whitelist()(allow_guest=True)
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
GET http://192.168.1.4:8000/api/method/renfield.api.make_stock_entry?serial_no=8906001055891

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

Pragnya

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:

@frappe.whitelist()(allow_guest=True)
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.