CRM and CX Blog Posts by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
Yogananda
Product and Topic Expert
Product and Topic Expert
222

This blog article is primarily aimed at developers who are looking to enhance their understanding of the ETag and If-Match headers. By ensuring the correct implementation of these headers, developers can effectively update field values in SAP Sales Cloud and Service Cloud & ESM APIs. This approach not only guarantees data integrity but also helps reduce the high number of concurrent API usages, leading to improved performance and reliability.2025-02-20_21-36-18.png

ETags & If-Match

  1. The Developer makes a GET request to the CNS server.
  2. The server responds with a 200 OK status, including the content requested and an ETag header.
  3. The client caches the response and the ETag value.
  4. For subsequent requests to the same resource, the client includes the If-Match header with the ETag value it has cached while updating the field value or the record.
  5. The server regenerates the ETag independently and checks if the ETag value sent by the client matches the generated one.
    • If they match, the server responds with a 200 OK  Modified status, indicating that the client’s cached version is valid, and the field is updated with request body is sent in PATCH request.
    • If they don’t match, the server responds with a 412 Precondition Failed status, indicating that the request conditions were not met or 428 status, Request sent is incorrect

chart.png

How If-Match works with ETag to prevent mid-air collisions during simultaneous updates.

chart (1).png

Explanation:

  • Client1 and Client2 both make GET requests to the server and receive the same ETag value ("12345").
  • Both clients cache the response along with the ETag value.
  • When both clients attempt to update the resource simultaneously, they include the If-Match header with the cached ETag value.
  • The server regenerates the ETag independently for each request.
    • If the ETag matches, the server updates the resource and responds with a 200 OK status.
    • If the ETag does not match (due to another update), the server responds with a 412 Precondition Failed status, preventing the update and ensuring data integrity.

This mechanism helps prevent mid-air collisions by ensuring that only one client can successfully update the resource if the ETag matches, while others receive a failure response if the resource has been modified by another client.

Practical examples of using If-Match to ensure data integrity and consistency

Example 1 : How to get ETag value using GET Method - Response Header contains "Last Modified Date"2025-05-07_12-25-31.png
Example 2 : How to pass ETag value to PATCH method to update the field - Response Header Matches and updates the field value with Response 200 OK2025-05-07_12-34-01.png
Example 3 : How to pass ETag value to PATCH method to update the field with Incorrect If Match - Response Header validates against ETag and If-Match - If not Matched Response with 412 is sent2025-05-07_12-33-32.png
Example 4 : How to pass ETag value to PATCH method to update the field with Incorrect Header - Response Header validates against ETag and If-Match - If Header is incorrect 428 is sent2025-05-07_12-46-52.png

A few key points to keep in mind:

  • Always wrap your ETag values in double quotes when sending them
  • If the client is a performing in browser (SSC V2 UI), it’ll automatically manage the cache and send conditional requests without any extra work.

 

References

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag