Dear community,
I am trying to set the Field "Title" in a list item to a new value by using the SP REST API. For reference, I followed the documentation about updating list items.
My update step looks like this
POST /[uri]/GetByTitle('Pages')/Items(8)
Headers
{
"If-Match": "*",
"X-HTTP-Method": "MERGE",
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json"
}
Body
{
'__metadata': {
'type': 'SP.Data.PagesItem'
},
'Title': 'newTitle'
}
The response is
{
"status": 400,
"message": "The property '__metadata' does not exist on type 'SP.Data.PagesItem'. Make sure to only use property names that are defined by the type.\r\nclientRequestId: 6d32167d-5a15-44e4-8e22-0be00a17a2c9\r\nserviceRequestId: ce964a9f-b048-2000-6cd2-3e91db9c86af",
"source": "[uri]/_api/web/lists/GetByTitle('Pages')/items(8)",
"errors": [
"-1",
"Microsoft.SharePoint.Client.InvalidClientQueryException"
]
}
Strangely enough, when getting this item like so
GET [uri]/_api/web/lists/GetByTitle('Pages')/Items?$select=Id,%20Title,%20FileRef&$filter=FileRef%20eq%20%27[uri]/Pages/[pagename].aspx%27
I receive this
{
"d": {
"results": [
{
"__metadata": {
"id": "24a84d64-f9f5-42f2-b487-43048e8d5889",
"uri": "[uri]/_api/Web/Lists(guid'68025e38-a5b3-4181-be51-b3a7f737d373')/Items(8)",
"etag": "\"191\"",
"type": "SP.Data.PagesItem"
},
"Id": 8,
"Title": "[pagetitle]",
"ID": 8,
"FileRef": "[uri]/[pagename].aspx"
}
]
}
}
This shows me, that there is indeed a property '__metadata' and the type 'SP.Data.PagesItem' is also correct. So why is it not working? 🙂
Thanks for your help,
Michael