How to send POST request from my ERPNEXT server to other server and reponse result

Hi everybody,

Im a newbie in ERPNEXT. Someone help me?

Im want when one sales invoice submited, will creat new document on other server (throught API).

I need send POST request from my ERPNEXT server to other server.

I tried insert python code to sales_invoice.py but not working.

Someone help me?

Thank a lot.

done it before … you go to the hook and point the event to your custom app method path
i used frappe client library which is a python lib make your life awesome to integrate with erpnext i have use it in django and frappe for them to send data to Destination Server

Thanks for reply.
But im a newbie. Would you help me step by step ?

this is the library

you can see examples how to use it in example.py files

Don’t change the ERPNext code for your instance as this will most probably break updates. (Interesting post)

You can use the GUI to create a webhook: Webhooks

In your case it would be:

DocType : Sales Invoice
Doc Event : on_submit
Request URL : https://your-api-server.tld

This will send a POST request to your-api-server every time a Sales Invoice is submitted.

For authentication, you can add your credentials with the authorization header. You can also specify custom keys for each ERPNext fieldname, so your API will understand the request.

If you really need to, you can create webhook from python with something like this:

import frappe

try:
    webhook = frappe.get_doc({
        "doctype": "Webhook",
        "webhook_doctype": "Sales Invoice",
        "webhook_docevent": "on_update",
        "request_url": "https://your-api-server.tld",
    })

    webhook.insert()
    frappe.db.commit()
        
except Exception as e:
    # handle exeption
5 Likes

ERPNext v13 comes with event streaming wich makes sending documents from one instance to another much easier:

https://docs.erpnext.com/docs/user/manual/en/automation/event_streaming

Dear @rmeyer i read ur post regarding post data through api to other server, in which u said that using webhook we can post different fields ,

I am looking for same solution can u plz let me know that how i can send specific fields of sale invoice to other server through API having different fields names,

For example : in erpnext sale invoice we have totalbillamount field name but in my online server it have totalsalevalue.

Now i want to know that how i can send totalbillamount value to totalsalevale field using json through API.

Thanx in advance.

Hi @erpnext786, have a look at this example. Here the field “name” is mapped to “id” and the field “items” is mapped to “lineItems”.

Is it require to make changes in backend …?

Secondly plz help in another issue that when i m sending Post request my ERPnext server to Online Api server (on asp.net with Sql) in response Api server sends me unique invoice number , but i don’t know how to get that response/number and how to sale it against sale invoice.

E.g : i am sending post request through webhoock to my Api server on submission of sale invoice with my sale invoice data , in response my Api server send 0011223344-55 serial number .

In erpnext i dont know where i can see response and ho to get that response and how to save it in my erpnext db against sale invoice.

Waiting for your kind response . Thanx in advance bro.

Why? The example I linked is purely in the frontend.

With Webhook you can only send data. For handling any response you probably really need a backend method.