restsharepointsharepoint-2010sharepoint-2013sharepoint-workflow

How to update share point 2013 list item in rest service


This is my Rest service to update list item

When I run this URL in post man I get an error

The request ETag value __metadata.etag does not match the object's ETag value "8".

But If I change IF-MATCH value in header as *, it's updating properly. Why I am getting an error if use ETag?


Solution

  • You are using the ETag incorrectly. The ETag will correspond to the item's Version not the item's ID.

    The best way to test this is to do a get request for the item and look at the metadata for the ETag property. You will see something similar to this

    {
        "__metadata": {
            "id":"Web/Lists(guid'xxxxxxxx')/Items(1)", 
            "uri":"https://site.sharepoint.com/site/subsite/_api/Web/Lists(guid'xxxxxx')/Items(1)",
            "etag":"\"12\""
        } 
    }
    

    Notice the formatting of the ETag.

    I can't think of any good reason to use the IF-MATCH for a specific ETag in the case of updating the item. The request parameter for the ID should be more than sufficient. Checking versioning with ETags is needed when wanting to PUT, MERGE, or DELETE a specific version of an item.

    Check this Working with lists and list items with REST for more information.