microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
704 stars 252 forks source link

Excel Update tablerow PatchAsync not available #2699

Closed martinlammers closed 1 month ago

martinlammers commented 1 month ago

I am trying to update a row in a table using GraphApi. According to the documentation, the code should look like this:

`using Microsoft.Graph.Models; using Microsoft.Kiota.Abstractions.Serialization;

var requestBody = new WorkbookTableRow { Index = 99, Values = new UntypedString("values-value"), };

var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Workbook.Tables["{workbookTable-id}"].Rows["{workbookTableRow-id}"].PatchAsync(requestBody);`

I get the error message “The Api you are trying to use could not be found.”

The http call according to the documentation looks like this and does not work either. I get the same error message in Graph Explorer:

`PATCH https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/tables/{id|name}/rows/{index} Content-type: application/json

{ "index": 99, "values": "values-value" }

If I call the following in Graph Explorer, it works:

https://graph.microsoft.com/v1.0/drives/drive-id/items/driveItem-id/workbook/tables/table-id/rows/**itemAt(index=0)** { "values": "values-value" }

I think PatchAsync is missing. The call should look like this:

`var requestBody = new WorkbookTableRow { Values = new UntypedArray(new List { new UntypedArray(new List { new UntypedString("column1-value"), new UntypedString("column2-value") }) }) };

var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Workbook.Tables["{workbookTable-id}"].Rows.ItemAtWithIndex(99).PatchAsync(requestBody);`

andrueastman commented 1 month ago

Thanks for raising this @martinlammers

This looks to be an issue with the API metadata and API implementation you can however work around this in the meantime by making the request to the undocumented endpoint as below.

            var requestInformation = graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Workbook.Tables["{workbookTable-id}"].Rows.ItemAtWithIndex(99).ToGetRequestInformation();
            requestInformation.HttpMethod = Method.PATCH; // set the method to PATCH
            requestInformation.SetContentFromParsable(graphClient.RequestAdapter,"application/json", requestBody); // set the content of the request to the workbookTableRow object
            var response = await graphClient.RequestAdapter.SendAsync<UntypedNode>(requestInformation, UntypedNode.CreateFromDiscriminatorValue);
martinlammers commented 1 month ago

Thanks that works!