Make a POST Rest Call from ERP Next

Hi Guys,

I’ve tried all I could but I still can’t seem to figure it out.

I want to make a Post Rest call from erpnext as soon as a Sale Invoice is paid. I’ve noticed that the doc type changes to Payment Entry once you click on Make Payment.

I would like to pass the payment details of the invoice on to another server as soon as the invoice is marked paid. Say the URL for the endpoint is: http://myserver:8001/middlewareserver/callback/

The information I would like to pass to the middleware is:

“doctype”: “Sales Invoice”,
“name”: “ACC-SINV-2018-00046”,
“creation”: “2018-09-18 22:01:03.201931”,
“customer_name”: “ALEX WAYNE”,
“customer”: “CUST-2018-00054”,
“grand_total”: 150,
“outstanding_amount”: 0

If it’s not possible to get the invoice data directly from the Sales Invoice doc type, then from the Payment Entry doc type, I could get:

“party_balance”: 150,
“creation”: “2018-09-18 21:24:10.524375”,
“name”: “ACC-PAY-2018-00025”,
“paid_amount”: 120,
“title”: “CUST-2018-00058”

Could you assist me in knowing how I can implement that call to the middleware server and pass that information.

Thanks in advance.


@kenince share the code snippets you tried

@hereabdulla here you go…


def update_middleware(doc, method):
if doc.references:
for item in doc.references:
header = {‘content-type’: “application/json”, }
url = ‘http://myserver:8001/middlewareserver/callback/
data = {
“reference_doctype”: item.reference_doctype,
“creation”: item.creation,
“paid_amount”: item.total_amount,
“customer”: item.reference_name
res =, data=data, haeders=header)
return res


“Payment Entry”: {
“on_submit”: [“erpnext.regional.france.utils.create_transaction_log”, “erpnext.accounts.doctype.payment_request.payment_request.make_status_as_paid”,
“on_trash”: “erpnext.regional.check_deletion_permission”

In the 15th line of your file you have a typo (‘haeders’)…That may be the issue.

1 Like

Thanks @chabito79 for noticing that. Let me fix this and try again. I’ll give feedback.