I am writing an API in Web API 2.0 on C# to perform various Actions with SharePoint List items.
I have tried the following code to update the Status Column of a List item:
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create("https://site.sharepoint.com/sites/OverDuePos/_api/web/lists/GetByTitle('Overdue POs List')/items(45)");
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.Method = "MERGE";
// endpointRequest.Headers.Add("X-HTTP-Method", "MERGE");
endpointRequest.Headers.Add("IF-MATCH", "*");
endpointRequest.Headers.Add("X-RequestDigest", null);
string stringData = "{'__metadata': { 'type': 'SP.Data.TestlistListItem' }, 'PO_x0020_Status': 'whatever'}";
endpointRequest.ContentLength = stringData.Length;
string result = string.Empty;
endpointRequest.Headers.Add("Authorization",
"Bearer " + "token");
StreamWriter writer = new StreamWriter(endpointRequest.GetRequestStream());
writer.Write(stringData);
writer.Flush();
WebResponse wresp = endpointRequest.GetResponse();
using (StreamReader sr = new StreamReader(wresp.GetResponseStream()))
{
result = sr.ReadToEnd();
}
The code is throwing the following Error:
'The remote server returned an error: (500) Internal Server Error.'
Similarly I have to update various columns in Multiple Lists.
Also, I cannot Hardcode any user and Password in the code.
Can anyone Help me sorting this Out?