Try ERPNext Buy Support Partners Foundation

How to call rest API for rename, cancel and submit

Hi,

I am working with rest API using python and in that I am succeeded with get, post, put, delete operations for Master data like item, supplier, customer. But don’t know how to rename, cancel and submit the existing document. Please anyone help me on this.

You can create a document by sending a PUT request to the endpoint, /api/resource/{doctype}/{name} . This acts like a PATCH HTTP request in which you do not have to send the whole document but only the parts you want to change.

https://frappe.io/docs/user/en/guides/integration/rest_api

Hi @youssef,

Here is my code like what you said, but it doesn’t work for just renaming the existing customer from POST to POST1

import requests
import json
def send_to_erpnext():
   
    url = "https://pranera.erpnext.com/api/resource/Customer/POST"
    headers = {
        'Authorization': "token "+ "xxxxxxxx" + ":" + "xxxxxxxx",
        'Accept': 'application/json'
    }
    data = {"customer_name": "POST1", "gst_status":"Registered Dealer", "constitution":"LLP", "customer_group":"PT/TirupurExporter", "territory":"Tamil Nadu", "customer_type": "Company"}
    all_data = json.dumps(data)
    text = []
    response = []
    response = requests.request("PUT", url, headers=headers, data=all_data)
    print(response.json())    

send_to_erpnext()   

Please do the needful.

you can see this Unofficial documentation of the Frappe / ERPNext API.

and this:
https://app.swaggerhub.com/apis/alyf.de/ERPNext/11

Hi @youssef,

First I wish to say thanks for your response. I saw your link and read the documentation, In that you have mentioned the code for update the specific document using put method, which I have already tried and got success.

But here i am seeking help for renaming, cancelling and amending the document. Kindly do the needful.

1 Like

Have you tried this solution?

For cancelling doc :

and for submit you can use same method with {“docstatus”: 1}

Hi @youssef,

Thanks for your response, I have tried using online editor to import frappe, but got a error and also I have doubt in when to call this rename function, whether after rest API or before API. Could you please help via screen sharing.
Kindly do the needful.

you have create this function in a custom app and then call it from api with /api/method/{dotted.path.to.function}

Hi @youssef,

Can I import this frappe module in Django framework, will it work? Kindly let me know.

Thanks in advance.

As I now you can’t do this.

@youssef Is there way to submit the sales invoice using rest API in tkinter python? Please help me on this.