2
votes

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))
            {
            }
        }
    }
1
Looks like a duplicate of this one: stackoverflow.com/questions/41285403/…Tracy

1 Answers

0
votes
 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";