I am getting this error while trying to post data to SharePoint list. It has one lookup field PostCategory
.
{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected.\"}}}","responseJSON":{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected."}}},"status":400,"statusText":"error"}
I have created another lookup field but there I was able to update by rest, but not able to update to the previous field.
PostCategory is the exisitng field and I have added Newcategory field. Both are lookup field, but there is some difference as there is no results array in NewCategory. I think may be this is the reason I am not able to post data to PostCategory field.
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Posts')/items(1)",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
data: "{__metadata:{'type':'SP.Data.PostsListItem'},PostCategoryId: 4}",
success: function(data) {
console.log(data.d.results);
},
error: function(error) {
console.log(JSON.stringify(error));
}
});