microsoftgraph / msgraph-sdk-dotnet

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

Workbook session not persisting changes #2489

Open craig-blowfield opened 6 months ago

craig-blowfield commented 6 months ago

Describe the bug

I am trying to update workbook table rows within a created session (passing 'workbook-session-id' in the header) to improve the performance of my code but no changes occur, either immediately after update call or on session close.

Using the graph API explorer seems to work (create session, update row with session id, close session), although the changes occur immediately after row update, rather than on session close. Not sure if this is expected behavior.

Although not related to this, but in pursuit of improving the performance of my code I tried to use batch requesting, with and without a session id, and this also didn't work.

Additionally, it seems lots of your example code is incorrect (e.g. Close session c# snippet).

Expected behavior

Workbook table Rows are updated when used with a session

How to reproduce

The following works when the code to add the session id to header is removed

            var workbookFileDriveItem = await MsGraphHelpers.GetDriveItemWithAbsoluteUrl(graphClient, "https://mysharepointfilelocation.xlsx");

            var tableName = "mytable";
            var totalColumns = 134;
            var columnIndex = 131;
            var startRowIndex = 60;

            // create workbook session
            var session = await graphClient
                    .Drives[workbookFileDriveItem.ParentReference.DriveId]
                    .Items[workbookFileDriveItem.Id]
                    .Workbook
                    .CreateSession
                    .PostAsync(new Microsoft.Graph.Drives.Item.Items.Item.Workbook.CreateSession.CreateSessionPostRequestBody { PersistChanges = true });

            var cellValues = new string[] { "MyCellValueA", "MyCellValueB" };
            var rows = new string[][] {
                cellValues
            };

            // workaround due to broken SDK
            List<UntypedArray> jsonRows = CreateRowValues(totalColumns, columnIndex, rows);

            // update row with session
            var excelUpdateRowResponse =
                    graphClient
                            .Drives[workbookFileDriveItem.ParentReference.DriveId]
                            .Items[workbookFileDriveItem.Id]
                            .Workbook
                            .Tables[tableName]
                            .Rows["$/ItemAt(index=" + startRowIndex + ")"]
                            .PatchAsync(new UpdateWorkbookTableRowBody
                            {
                                Rows = jsonRows
                            }, config =>
                            {
                                config.Headers.Add("workbook-session-id", session.Id);
                            });

            // close session
            await graphClient
                    .Drives[workbookFileDriveItem.ParentReference.DriveId]
                    .Items[workbookFileDriveItem.Id]
                    .Workbook
                    .CloseSession.PostAsync(c =>
                    {
                        c.Headers.Add("workbook-session-id", session.Id);
                    });

SDK Version

No response

Latest version known to work for scenario above?

No response

Known Workarounds

No to use workbook sessions, which decreases performance

Debug output

Click to expand log ``` ```

Configuration

No response

Other information

No response

craig-blowfield commented 6 months ago

Could I have a response to this raised issue please as it is holding up completing client work

craig-blowfield commented 6 months ago

Also note that I tried the documented table update row endpoint

https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{drive-item_id}/workbook/tables/{table-name}/rows/{index}

with body

{ "index": 1 ... }

Which fails with

{
    "error": {
        "code": "ApiNotFound",
        "message": "The API you are trying to use could not be found. It may be available in a newer version of Excel. Please refer to the documentation: \"https://docs.microsoft.com/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets\".",
        "innerError": {
            "code": "apiNotFound",
            "message": "The API you are trying to use could not be found. It may be available in a newer version of Excel. Please refer to the documentation: \"https://docs.microsoft.com/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets\".",
            "date": "2024-05-16T10:43:54",
            "request-id": "e16d020f-d381-40e0-a93b-84d14ae96988",
            "client-request-id": "bdfa2156-beb5-7cd1-261a-2392d83beff0"
        }
    }
}

But using ItemAt as shown in my code works

andrueastman commented 3 months ago

Any chance this is still an issue @craig-blowfield? As this looks to be API related, the place for API questions would be at https://aka.ms/askGraph

craig-blowfield commented 3 months ago

Yes @andrueastman I have updated to the latest version and yes it is still an issue.

I have followed the SDK documentation for working with excel sessions and the SDK is allowing me to call the API in this manner, so its an SDK issue, not an API issue.