Microsoft.Graph Sharepoint api allows to update list item https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/listitem_update using PATCH request. But how to generate a correct request?
using (HttpClient pacthClient = new HttpClient())
{
var mediaType = new MediaTypeWithQualityHeaderValue("application/json");
pacthClient.DefaultRequestHeaders.Accept.Add(mediaType);
pacthClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userToken);
using (HttpRequestMessage requestMessage = new HttpRequestMessage(new HttpMethod("PATCH"), $"{uri}/{id}"))
{
requestMessage.Content = byteArrayContent ???
using (HttpResponseMessage responseMessage = await pacthClient.SendAsync(requestMessage))
{
}
}
}
string addItemJsonString = "{\"name\":\"Test Visit\"}";
string requestUrl = "https://graph.microsoft.com/v1.0/sites/{siteID}/lists/{listID}/items/{itemID}/fields";
HttpClient client = new HttpClient();
HttpRequestMessage message = new HttpRequestMessage(new HttpMethod("PATCH"), requestUrl);
message.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
//set the request body
message.Content = new StringContent(addItemJsonString);
HttpResponseMessage response = await client.SendAsync(message);
if (response.IsSuccessStatusCode)
{
responseString = await response.Content.ReadAsStringAsync();
}
else
responseString = "Error in response";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.