I am successfully connected with SharePoint Online and successfully Updated the List using Rest Api.
Now I am trying to Get item details using ItemID using the following C# Code:
try
{
Uri uri = new Uri(MasterData.SiteURL);
using (var client = new SPHttpClient(uri, MasterData.UserID, MasterData.PWD))
{
var listTitle = "Overdue POs List";
var itemPayload = new { __metadata = new { type = "SP.Data.Overdue_x0020_POs_x0020_ListListItem" } };
var endpointUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items({2})", uri, listTitle, ItemID);
var keyValues = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("Authorization", "Bearer "+accessToken)
};
HttpContent content = new FormUrlEncodedContent(keyValues);
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var response = httpClient.GetAsync(endpointUrl).Result;
var result = response.Content.ReadAsStringAsync().Result;
var status = (JsonConvert.DeserializeObject<OverduePOs>(result.ToString())).PO_x0020_Status;
return status;
}
}
catch (HttpRequestException ex)
{
return "";
}
The response is successfully coming in XML Format but I am unable to Desearilize that in JSON:
Response:
Exception:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: <. Path '', line 0, position 0.'
can anyone Help to parse results in JSON?
httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); // Specify JSON format
for your request and see if it returns inJSON
format?