How to make post REST API call from erpnext server to another server?

Hello,
Can anyone show me how to make Rest api call from erpnext to other server ? i want to know exactly how to get the CSRF token from frappe to get the logged user in erpnext.
thanks regard,
Joseph

for crf
frappe.csrf_token
for request from other Erpnext you can use requests library

Thanks for replay @ahmad18189
that library u share is to make request to another server of erpnext
but i want to make call to another server not erpnext one, is that possible to do that ?

that library u share is to make request to another server of erpnext

used by frappe and any python server.
it can hit whatever api of whatever server and recive responce in your server

Please check the link below

hmm… i see that’s the way to make api call from erpnext to another server, but now i have another problem. how to make the api call from the other server to erpnext server ? to make the server sync between erpnext server and my other server. how to do that ? im still looking for the solution

Have you tried using the Frappe Client class?

1 Like

Nope, i haven’t try that, but actually this one might help me

The whole point of a CSRF token is to follow Same-Origin Policy. I’d recommend you to use the frappeclient interface for connecting with other ENext servers. You can generate a Session object with the same. It also has enough interface for you to initiate a session remotely with desired SIDs.

hello @achillesrasquinha
hmm… but i want to connecting from non erpnext server to erpnext server and i want to know what plugin / library should i use in php ? i already tried with Curl php but it seems doesn’t work for me.
Thanks

You can use the FrappeClient (Link) library here.

To install it. Simply,

git clone https://github.com/frappe/frappe-client frappe-client
pip install ./frappe-client

Within your app, you could then use authenticate as follows

from frappeclient import FrappeClient

client = FrappeClient("example.com", "user@example.com", "password")

…where example.com is your ENext instance.

Calling the API is then as simple as

>>> data = frappeclient.post_api('frappe.handler.ping')
>>> data['message']
"pong"
2 Likes

Hello, @achillesrasquinha thanks for the library, but how to use frappe client in php code ? im trying to get data from erpnext to my php codes. that’s why i need to know what plugin or library should i use in php to get data from erpnext.
Thanks :slight_smile:

Good Day

Did you manage to get something for PHP?
I also looked at ajax, but still no clue how to query ERPNext without FrappeClient.

Thank you

Albertus Geyser

See a simple video on how to implement API calls in ERPNext here: ERPNext/Frappe: Making API Calls - YouTube

Thanks for the video, Would you please share any example link to post data into ERP Next. Say Inserting data to a document, like patient registration.

Hello, I will do a short tutorial on this. Sounds like you are talking of a webhook.

Great ! I watched your all videos and it will be great if you can build and share your knowledge for Webhook and API to push data into ERPNext from external and also to push data from ERPNext to other apps.

Great! I will certainly prioritise this. It will be coming soon.

1 Like

Hi, I request again to post the video for post doctype

Please see this resource: The Ultimate ERPNext API Mastery Series - Code with Karani