- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 10:45 PM
What is the difference between the PUT and PATCH methods in the REST API integration
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 10:51 PM
Hi @Shantharao ,
PATCH
• Updates only specific fields in an existing record.
• If the record doesn’t exist, the PATCH method will fail (e.g., 404 Not Found).
• Think of it as editing just one or two pieces of information in a record.
Example:
If there’s an incident with Number: INC0001234 and you want to update just the Short Description field:
PATCH /api/now/table/incident/INC0001234
Request Body: { "short_description": "Updated Short Description" }
This updates only the short description while leaving other fields, like the priority or state, unchanged.
PUT
• Replaces the entire record with new information.
• If the record doesn’t exist, PUT will create it.
• Think of it as rewriting all the fields of a record.
Example:
If there’s an incident with Number: INC0001234, and you want to completely replace it with new data:
PUT /api/now/table/incident/INC0001234
Request Body: {
"short_description": "New Short Description",
"priority": "2 - High",
"state": "In Progress"
}
This will replace all fields of the record with the new data provided. If INC0001234 doesn’t exist, it will create a new incident with this data.
Key Difference:
PATCH: Updates only the fields you specify. Example: Changing just the Short Description of an incident.
PUT: Replaces the entire record. Example: Rewriting the incident with new values for Short Description, Priority, and State.
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 10:49 PM
Hello @Shantharao
PATCH: it is used to update an existing entity with new information. You can't patch an entity that doesn't exist. You would use this when you have a simple update to perform, e.g. changing a user's name
PUT: it is used to set an entity's information completely. PUTting is similar to POSTing, except that it will overwrite the entity if already exists or create it otherwise. You could use a PUT to write a user to your database that may already be in it.
Please refer Harsh reply in the below thread:
Please mark the answer as helpful and correct if helped.
Kind Regards,
Ravi Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 10:56 PM
Hi Ravi,
Thank you for the quick response,
I have seen that thread already but didn't understand properly, could you please provide an example briefly in ServiceNow terminology
Thaks in advance for your reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 11:13 PM - edited 11-22-2024 11:40 PM
Hello @Shantharao
PUT is used when we want to replace the entire resource where as Patch is used to when we want to modify specific resource.
As Anand said, PUT will create a new record if it doesn't exist.
example for PATCH:
PATCH /api/now/table/change_request/abcdef123456
{
"short_description": "Upgrade database servers - Phase 2",
"priority": "1 - Critical"
}
Effect:
The short_description and priority fields are updated.
Fields like sys_id, number, state, and risk remain unchanged.
Resulting Change Request Record:
{
"sys_id": "abcdef123456",
"number": "CHG0001234",
"short_description": "Upgrade database servers - Phase 2",
"priority": "1 - Critical",
"state": "New",
"risk": "Low"
}
Please refer below videos:
The SAAS with ServiceNow is a very good resource:
https://youtube.com/playlist?list=PLzTvAeLiW8Ae4-8eJWNhzFyTqovD9LaaR&si=LDIpkPBntpSGqbDK
You can also refer below video, where she explained using postman:
https://youtu.be/HmuCXNT7YKE?si=d4aYil8WDIJA8VTM
Please mark the answer as helpful and correct if helped.
Kind Regards,
Ravi Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 10:51 PM
Hi @Shantharao ,
PATCH
• Updates only specific fields in an existing record.
• If the record doesn’t exist, the PATCH method will fail (e.g., 404 Not Found).
• Think of it as editing just one or two pieces of information in a record.
Example:
If there’s an incident with Number: INC0001234 and you want to update just the Short Description field:
PATCH /api/now/table/incident/INC0001234
Request Body: { "short_description": "Updated Short Description" }
This updates only the short description while leaving other fields, like the priority or state, unchanged.
PUT
• Replaces the entire record with new information.
• If the record doesn’t exist, PUT will create it.
• Think of it as rewriting all the fields of a record.
Example:
If there’s an incident with Number: INC0001234, and you want to completely replace it with new data:
PUT /api/now/table/incident/INC0001234
Request Body: {
"short_description": "New Short Description",
"priority": "2 - High",
"state": "In Progress"
}
This will replace all fields of the record with the new data provided. If INC0001234 doesn’t exist, it will create a new incident with this data.
Key Difference:
PATCH: Updates only the fields you specify. Example: Changing just the Short Description of an incident.
PUT: Replaces the entire record. Example: Rewriting the incident with new values for Short Description, Priority, and State.
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand