I wrote a .py file in apps/erpnext/erpnext/api/post/login_api.py so now how can a 3rd party call this api?
Is there any way I can check?
I wrote a .py file in apps/erpnext/erpnext/api/post/login_api.py so now how can a 3rd party call this api?
Is there any way I can check?
Hi @LeTienIT:
Use
@frappe.whitelisted()
decorator to allow client calls.
From client side just call to yoursite.com/api/method/yourmethod
See this
https://frappeframework.com/docs/user/en/guides/basics/frappe_ajax_call
And this
https://frappeframework.com/docs/user/en/api/rest#remote-method-calls
Hope this helps.
I can’t do it. I’m running on a virtual machine so the way to access is
> "http://ip/api/post/login_api/login_function"
But the end result is:
Try http://ip/api/method/login_function
That still doesn’t work? Besides creating the login_api file, do I have to configure anything else in other files?
Hi @LeTienIT:
How is your method defined? Please, paste here your code (mask any private data …). And show here how are you calling the function.
Thanks.
I simply created a file in the link below and printed out a message.
frappe-bench/apps/erpnext/erpnext/api/post$ nano login_api.py
How are you calling the function from outside? Please, paste exactly url (mask ip or server name if you want …)
http://<ip>/api/post/login_api/login_function
rs:
Hi @LeTienIT:
http://<ip>/yourapp/yourpathtofile.yourfunction
yourapp
= custom app name
yourpathtofile
= dotpathed method to the file
yourfunction
= method name
Example, you have a custom app named yourapp
. So under your bench folder, there will be a folder called “yourapp”. Inside this, you have another folder called “yourapp”, and inside this a folder called “api”. Here there is a file called test.py and your function inside called login_function (under @frappe.whitelist() decorator.
yourapp
----yourapp
--------api
------------test.py
Use
http://<ip>/api/method/yourapp.yourapp.api.test.login_function
You can use bench execute
command to test from console
Hope this helps.
Hi @LeTienIT:
It will work inside erpnext folder. But note that this is not recommended at all, because your changes will be gone with any further update.
Hope this helps.
The problem has been resolved. however the correct path should be /api/method/appname.“path from app to needed function”.
Previously, I had an unresolved problem: testing how the function behaves over time. That is, I want a function to be executed every new day. I tested it in console and it worked. However, when I added hooks.py in daily, the next day I checked the results and there was no change. Do you have a solution?
Hi @LeTienIT:
Check if other scheduled jobs are working (search scheduled job on awesome bar). If are not working, maybe your scheduler is stopped or paused. In this case …
bench scheduler enable
bench scheduler resume
Note: Please, in this cases is better to start other thread on forum with the new question. It will be easier to other ones to finding solutions.
Hope this helps.