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.
ETags & If-Match
- The Developer makes a GET request to the CNS server.
- The server responds with a 200 OK status, including the content requested and an ETag header.
- The client caches the response and the ETag value.
- 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.
- 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

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

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"
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 OK
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 sent
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 sent
A few key points to keep in mind:
References
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag