- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 05:38 AM
Hi All,
I am using REST API EXPLORER and i selected PUT methods and selected user table and then given one sys id record
then i updated email value and its working --> after sending the rest call --> email id got updated in target table( user table)
then i did the same using PATCH -- > email id got updated
so now the question if both PUT and PATCH are doing the same job , then what is the difference ?
Please provide your inputs
Thank you,
Shabbir Shaik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 06:10 AM
- Consider there's a record with information like name, email, age, department, role etc.
- The objective is to update age for that record
PUT Method:
- If you use the PUT method, you need to send the entire records' data in the payload even if you only want to change one field.
- If the data populated in the age field has to be updated, the entire record's data from every field like age, department, role, name, email everything has to be sent in the payload of the PUT call to third party. If you leave out any information, it will be erased or set to default.
PATCH Method:
- If you use the PATCH method, you can just send the new age without sending out other information of name, email, department.
- Basically PATCH is to make partial changes for a record.
Breakdown :
PUT : To overwrite the entire record with the changes done at the places desired while data at rest of the places remaining unchanged
PATCH : To make change exactly where it is intended
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 10:41 AM
Hi Shreya,
I got theoretical explanation its very clear , can we test the same with servicenow REST API Explorer / POSTMAN ?
Thank you,
Shabbir Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @ShreyasK0030
I tried both the Rest API Methods (PUT & PATCH) provided in the Table API via Postman and used the same payload for both requests. Here are my findings -
Test 1 - a new value for a single field - {"field_name":"New Value"}
The result was same for both the requests i.e. only that field was updated and the rest fields were unchanged (or not set to their respective default values)
Test 2 - empty payload - {}
The Result was again same for both the requests i.e. no change occured in the record whereas I suppose by your logic, the entire record fields should have been set to their default values for PUT Request.
Here is the documentation for these HTTP Methods for your reference.
Table API Documentation
Table - PATCH /now/table/{tableName}/{sys_id}
Updates the specified record with the name-value pairs included in the request body.
Request body parameters (XML or JSON)
name-value pairs : Field name and the new value for each parameter to update in the specified record.
Response body parameters (JSON or XML)
name-value pairs : Field names and values of all parameters within the specified record or those specified in the query parameters.
Table - PUT /now/table/{tableName}/{sys_id}
Updates the specified record with the request body.
Request body parameters (XML or JSON)
name-value pairs : Name-value pairs for the field(s) to update in the associated table. For example, to update the short description file, enter a name-value pair similar to the following: --data "{\"short_description\": \"my short desc\" }" \.
Response body parameters (JSON or XML)
name-value pairs : All fields (not just modified) with their associated values for the change request.
