Handling ETag value on SharePoint REST API Updates

ETag value is a part of the HTTP protocol that allows concurrency control and web cache validation. ETag is a broader topic when considered in general, but the main focus on this article is to discuss about REST API usage within SharePoint. ETag value is used whenever we make a POST request to a REST API endpoint. This is handled through the IF-Match request header. A sample request is displayed below.

REST API

So now lets see how this header works. Once we make a GET request, we receive an ETag value as a part of the meta data as you can see in the image below.

Image 2

This is a numeric value and it represent the resource version of the resource at the time the GET request is made. Given these data can be accessed by many users within the same time, there can be a difference of the data by the time a user attempts to update. (Simple concurrency issue). With ETag value we can check whether the values do match each other by the time the update operation is performed. If the values match, an update will be performed. If not, an error will be returned as follows.

Image 3

How to Handle this?

As I mentioned this earlier, we receive the ETag value once we make a GET request. So at the point of we receive it we can store that in a hidden field. At the point of update we can assign it to the IF-Match header. If we get the exception returned then we can prompt the user to perform the update with the latest information.

ESPC call for speakers 2024
 

How to Ignore?

Ignoring is simple. You can simply set the value to “*” which will ignore the ETag value and perform the update. This is shown in the first image.

About the Author:
Malin is a SharePoint Specialist at Exilesoft and has been working on SharePoint since SharePoint 2007. He has been involved in many custom development projects, intranets, search, and other SharePoint projects. Malin is a regular presenter in many forums, including Sri Lanka .NET Forum and SharePoint Sri Lanka. Malin also presented in the Share-The-Point Conference Southeast Asia and at ESPC15 in Stockholm.
Share this on...

Rate this Post:

Share: