ERPNext API: PUT not updating?

I’m trying to use the ERPNext API to Update a record in Postman.

The PUT only returns the data, and doesn’t update the record.

For example:

the erp . com/api/resource/Lead/CRM-LEAD-2022-00665

With a raw body of

 {
"status":"Lead"

    }

will return the Lead Record details, but it does not update the record.

Unfortunately, you may need to do some more troubleshooting. The PUT request you’ve got here works fine on my system (v14 latest stable release).

I can’t fathom what I would need to change…

Is there some option I need to enable inside ErpNext to allow records to be updated via REST?

There are no options; REST APIs are enabled automatically. The ERPNext UI itself leverages them.

My guess is that some business logic is preventing that particular Lead from changing its status. But without throwing an error. Somehow it’s just “skipping” the update, and returning back the JSON for the Lead.

I’m not familiar with Leads specifically. But I’ve definitely seen this happen with other DocTypes.

1 Like

I’m thinking I have something configured incorrectly in Postman (I can’t imagine what, though?).

When I send a Curl via PHP, it updates as expected. It’s just that when I try and send it via Postman that it won’t update…

May be, lack of permissions!

Try the same with tokens of administrator, it might work:

Authorization: token <api_key>:<api_secret>

If worked, replace tokens with user; and refine permissions for the users which needs to perform this operations.

Bump this issue. I am facing the same thing but am not able to figure out what is causing it.

The field shows its update but its not changing the data I am sending to through the request:

data = {“date”:“2018-10-08”}

Make sure to add this header:
"Content-Type" : "application/json", "Authorization": "token apikey:apisecret"

update_data = {“date”: “2020-01-01”}

api2 = requests.put(‘[website]/api/resource/[doctype]/’ + response[‘data’][0][‘name’], headers={**headers, ‘Content-Type’: ‘application/json’}, json=update_data)

I am doing exactly that. It shows that the doc is updated and returing code 200, but it is not changing anything. I btw tried json=update_data as well as data=update_data

Hi @mrPauwHaan:

This code works

import requests

# authentication with user and password
url = "http://yoursite.com/api/method/login"
data = {"usr": "youruser", "pwd": "yourpassword"}
response = requests.post(url, data=data)

# update doctype with put
url = "http://yoursite.com/api/resource/Item/item001"
data = {"valuation_rate": 100}
response = requests.put(url, json=data, cookies=response.cookies)

Anyway … connecting to Frappe systems from Python is really easy with FrappeClient library.

Check here …

Sample:

from frappeclient import FrappeClient

conn = FrappeClient("yoursite.com")
conn.login("youruser", "yourpassword")

doc = conn.get_doc('Item', 'item001')
doc['valuation_rate'] = 100
conn.update(doc)

Hope this helps.

Oh wow, I did not now about this client. Thanks!

However, I am using it now and still facing the same issue…

doc = Frappeclient.get_doc(Doctype, Docname)
                                doc['date'] = '2018-01-01'
                                Frappeclient.update(doc)

So it is showing in the doc that its updated, but the value is not updated. Only in changes it shows: “… last edited this”

I just tried it with login instead of Use token based authentication and now it works. I am still confused why this is the case and how I can make it work with token based authentication

Hi @mrPauwHaan:

To login with api_key/api_secret use authenticate method
It’s working well here …

from frappeclient import FrappeClient
conn = FrappeClient("http://yoursite.com")
conn.authenticate("yourapikey", "yourapisecret")
doc = conn.get_doc("Item", "test001")
doc["valuation_rate"] = 1200

It works anyway with requests …

url = "http://localhost:8000/api/resource/Item/test001"
data = {"valuation_rate": 1132}
headers = {
    "Content-Type": "application/json",
    "Authorization": "token adde0c34fcb27d2:605709860d9ffc6",
}

response = requests.put(url, json=data, headers=headers)
print(response.text)

Checked with date type field and it works well too … Try to use Recorder. Maybe it would bring some clues …

1 Like