I have a column with "ScheduledTimeSlot" already created in the SharePoint list but somehow i can't seem to update this column.
Verified that itemId, access token is correct as i am able to create item with another method, just having issues with updating items.
When i use
string addItemJsonString = "{\"ScheduledTimeSlot\":\"13XX17101310238\"}";
it works. But when i try the following method, it will give me bad request error 400. I'm pretty sure it's the format issue.
var root = new
{
fields = new Dictionary<string, string>
{
{ "ScheduledTimeSlot", scheduledTimeSlot }, //column to update
}
};
string addItemJsonString = JsonConvert.SerializeObject(root);
Full method below
public async Task UpdateSharePointListItem(string webApiUrl, string itemId, string scheduledTimeSlot, string accessToken)
{
Console.WriteLine(itemId);
Console.WriteLine(scheduledTimeSlot);
var root = new
{
fields = new Dictionary<string, string>
{
{ "ScheduledTimeSlot", scheduledTimeSlot }, //column to update
}
};
string addItemJsonString = JsonConvert.SerializeObject(root);
Console.WriteLine(addItemJsonString);
string requestUrl = config.ApiUrl + "v1.0/sites/" + config.SiteId + "/lists/" + config.ListId + "/items/" + itemId + "/fields";
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod("PATCH"), requestUrl);
message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
message.Content = new StringContent(addItemJsonString, Encoding.UTF8, "application/json");
HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
HttpResponseMessage response = await HttpClient.SendAsync(message);
Console.WriteLine(response);
}
I have also tried the solution here: How to PATCH data using System.Net.Http