Frappe ERPNext Update REST API

Hi I am new to Frappe, so I got started with the Frappe Rest API Docs. They are simple basic CRUD Apis. I was able to Create, Read and Delete a doctype, but not able to update/change it’s name or doctype_name e.g. In Territory Doctype I cannot update territory_name variable or name variable, the same goes for Currency, I cannot update currency_name variable or name variable. The same goes for Company, Customer Group etc but I can Create, Read and Delete them.

Why is the above so? and how can I update a doctype_name or name variable?

1 Like

HI @dansol,

Behind each DocType is a MySQL table. Almost always, the Primary Key of this table is the 'name’ column/field.

Consider the generic (not ERPNext) diagram below (which I shamelessly copied and pasted from the web). The table named 'MEASURE_TYPE' has a Primary Key field = “MEASUREMENTID”. This field is a foreign key in the other tables 'BLOUSE_MEASUREMENT', 'PARDI_MEASUREMENT', and 'LHENGA_MEASUREMENT'.

So, imagine you use a REST API to update the value of “MEASUREMENTID” in “MEASURE_TYPE”. This would break the relationship with the 3 other tables. Because their own “MEASUREMENTID” remained the same, original value.

This is why 'name' cannot be changed with a PUT request in ERPNext.

Instead, you must call a special function/endpoint called “rename”. Here’s a link to a previous thread where we talked about that:
Change item group unique name rest api

2 Likes

Thank you. Very Much @brian_pond

Another follow up I cannot seem to get the Supplier Type doctype.

I am using the online erpnext trial version which is at 14.0.2

How can I get access to Supplier Types, Customer Type?

I am not familiar with ERPNext v14 (it was only released 10 days ago)

However, in previous versions, “Customer Type” and “Supplier Type” were not DocTypes. They were just enumerated values.

See my screenshot below, showing “Customer Type” on the Customer DocType. This DocField is a “Select”. Which means a list of values stored in metadata. It doesn’t have its own table/DocType.

@brian_pond thanks that’s quite informative. is there a Rest API to return these enum values?
e.g. like how {{base_url}}/api/resource/Customer returns a list of customers

in the version you have?

That’s a really great question. The only way I know is by calling the REST API for “DocType” itself:

curl --request GET \
  --url http://127.0.0.1:8000/api/resource/DocType/Customer \
  --header 'Authorization: token abc123:efg567' \
  --header 'Content-Type: application/json' \
  --cookie 'sid=Guest; system_user=yes; full_name=Guest; user_id=Guest; user_image='

However, it feels a little weird/risky, to grant permissions to an API user, to query the DocType and DocField endpoints. :thinking:

Maybe there is another, better way to just fetch Options for a single DocField (without writing your own, custom endpoint, which is always possible)

Perhaps another developer will reply on this thread.

1 Like

Thanks @brian_pond you have been of great help. Would you know where I can get good documentation on ERP Next Rest APIs, I familiarize myself with it?

You’re very welcome.

The only site I know about is the official documentation:
https://frappeframework.com/docs/v14/user/en/api/rest

Everything else, I’ve learned from either finding existing examples within the Frappe and ERPNext code itself. Or trying things on my own. Or searching these forums for previous posts. :slight_smile:

@brian_pond there is also this link I got. Build, Collaborate & Integrate APIs | SwaggerHub with some other Rest API Docs.

It is where I have found the solution to initial problem I had. you can rename doctype using a POST to the end point: {{base_url}}/api/method/frappe.client.rename_doc

The post body should be:

{
  "doctype": "doctype",
  "old_name": "old_name",
  "new_name": "new_name"
}
2 Likes

Very cool; thanks for sharing that!

The team at alyf.de definitely know their stuff! (/salute @rmeyer )

3 Likes
13:09:19 system           | redis_queue.1 started (pid=1829)
13:09:19 system           | redis_cache.1 started (pid=1828)
13:09:19 system           | redis_socketio.1 started (pid=1827)
13:09:19 system           | web.1 started (pid=1830)
13:09:19 system           | watch.1 started (pid=1833)
13:09:19 system           | socketio.1 started (pid=1834)
13:09:19 system           | schedule.1 started (pid=1849)
13:09:19 system           | worker_short.1 started (pid=1842)
13:09:19 system           | worker_long.1 started (pid=1850)
13:09:19 system           | worker_default.1 started (pid=1852)
13:09:19 redis_queue.1    | 1835:C 12 Aug 2022 13:09:19.863 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13:09:19 redis_queue.1    | 1835:C 12 Aug 2022 13:09:19.863 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=1835, just started
13:09:19 redis_queue.1    | 1835:C 12 Aug 2022 13:09:19.864 # Configuration loaded
13:09:19 redis_queue.1    | 1835:M 12 Aug 2022 13:09:19.864 * Increased maximum number of open files to 10032 (it was originally set to 1024).
13:09:19 redis_queue.1    | 1835:M 12 Aug 2022 13:09:19.865 # Could not create server TCP listening socket 127.0.0.1:11001: bind: Address already in use
13:09:19 system           | redis_queue.1 stopped (rc=1)
13:09:19 system           | sending SIGTERM to redis_cache.1 (pid 1828)
13:09:19 system           | sending SIGTERM to redis_socketio.1 (pid 1827)
13:09:19 system           | sending SIGTERM to web.1 (pid 1830)
13:09:19 system           | sending SIGTERM to socketio.1 (pid 1834)
13:09:19 system           | sending SIGTERM to watch.1 (pid 1833)
13:09:19 system           | sending SIGTERM to schedule.1 (pid 1849)
13:09:19 system           | sending SIGTERM to worker_short.1 (pid 1842)
13:09:19 system           | sending SIGTERM to worker_long.1 (pid 1850)
13:09:19 system           | sending SIGTERM to worker_default.1 (pid 1852)
13:09:19 system           | worker_short.1 stopped (rc=-15)
13:09:19 system           | worker_long.1 stopped (rc=-15)
13:09:19 system           | worker_default.1 stopped (rc=-15)
13:09:19 system           | redis_socketio.1 stopped (rc=-15)
13:09:19 system           | redis_cache.1 stopped (rc=-15)
13:09:19 system           | schedule.1 stopped (rc=-15)
13:09:19 system           | socketio.1 stopped (rc=-15)
13:09:19 system           | web.1 stopped (rc=-15)
13:09:19 system           | watch.1 stopped (rc=-15)

do you know how to solve this problem

Please create a new thread for this issue.
In your new thread, you’ll want to include the full message. The important information for solving this is cut off

1 Like

I found out how to do it in ERP Next 14. Below is a link on how to do so:

Get doctype Metadata from Rest API - Developers - ERPNext Forum