I have a SharePoint list called "Search Results"
There is a field in the list called "Users" which I am trying to set to the value "Test" for a specific record ID.
$(window).load(function(){
try{
var item = {
"__metadata": { "type": "SP.Data.SearchResultsListItem" },
"Users": "Test"
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Search Results')/items(174)",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert('Field was updated!');
},
error: function(jqXHR, exception) {
alert(jqXHR.status);
}
});
}
catch(err){
alert(err);
}
});
I get error code of 400 returned.
In the Chrome console, I get a "Failed to load resource: the server responded with a status of 400 (Bad Request)" message and then a link.
When I click on the link, I can see the record in SharePoint on my screen. I can see my "Users" field.
Any suggestions on what I am doing wrong or how to proceed with troubleshooting?
Thanks in advance.
2
Answers
If there is space in List Name "Search Results", then the type shoule like this:
First try to run that URL in browser and check its returning results or not. Then go for the rest.
http://www.WebsiteURL.com/_api/web/lists/getbytitle(‘Search Results’)/items(174)
If its returning results find the metadate value from that and verify your metadata value as well..