locked
Graph Api to Update Excel Online RRS feed

  • Question

  • I am trying to update an Excel cell through Graph Api. My excel File is kept in a SharePoint Online Library.
    I am using the following PATCH method to update the Excel.
    Patch:
     https://graph.microsoft.com/beta/sites/{SiteDomain}/drives/{listDriveId}/items/{itemId}/workbook/worksheets('{sheetName}')/range(address='A5')  

    C# Code:
            HttpClient objclient = new HttpClient();
            objclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            var patchMethod = new HttpMethod("PATCH");
            var TableRowJson = "{\"values\": [[\"Updated\"]]}";
            var PatchBody = new StringContent(TableRowJson);
            PatchBody.Headers.Clear();
            PatchBody.Headers.Add("Content-type", "application/json");
            var workbookEndpoint = "https://graph.microsoft.com/beta/sites/" + SiteDomain + "/drives/" + listDriveId +"/items/"+ itemId +"/workbook/worksheets('"+ sheetName +"')/range(address='" + StatusIndex + "')";  
            var RequestMessage = new HttpRequestMessage(patchMethod, workbookEndpoint)
                                { Content = PatchBody };
            var ResponseMessage = await objclient.SendAsync(RequestMessage);

    I got the {listDriveId}, {itemId} using graph explorer.
    I am using a bearer token and Azure Active Directory app registration clientID.

    Problem: I am able to update the cell using above Patch call from C# console application, but it is not always updating the cell.
             Status of the call is showing always 200, ok but two out of ten calls are not updating the cell in SharePoint Online excel.

             When I have tried the same code in an Azure Function that is not updating very frequently. 8 out of 10 cases are not updating the excel.
             Again I am always getting 200, ok as response status.

    Any ideas why this is happening?
    Is anyone else is experiencing the same issue with Graph Api and Excel Online?
    Friday, April 3, 2020 1:11 PM