How to update workbook table row in JAVA?

Tugce Avsar 0 Reputation points
2023-02-28T20:10:18.33+00:00

Hello,

I opened a workbook in OneDrive and want to insert and update rows to it via the app. I was able to progress smoothly in getting and adding rows. But updating row data is not working.

I was able to update using Graph Explorer. I sent the sample request as HTTP method Patch.

PATCH https://graph.microsoft.com/v1.0/users/{userId}/drive/items/{itemId}/workbook/tables/{tableName}/rows/itemAt(index=2)
Content-type: application/json

{
  "values": "values-value"
}

I noticed 2 different things when I tried in java.

First, when I give the row index, the patch method appears. I get an error when I use the update method written in the Graph Api document. It gets ApiNotFound error.

Doc : https://learn.microsoft.com/en-us/graph/api/tablerow-update?view=graph-rest-1.0&tabs=java

graphClient.users(oneDriveProperties.getUserId())           
           .drive()
           .items(oneDriveProperties.getWorkbookId())
           .workbook()
           .tables(oneDriveProperties.getWorkbookTableName())
           .rows(String.valueOf(rowIndex)) 
           .buildRequest()
           .patch(workbookTableRow);

ERROR:

{
    "error": {
        "code": "ApiNotFound",
        "message": "Kullanmaya çalıştığınız API bulunamadı. Excel’in daha yeni bir versiyonunda mevcut olabilir. Lütfen şu belgeye başvurun: \"https://docs.microsoft.com/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets\".",
        "innerError": {
            "code": "apiNotFound",
            "message": "Kullanmaya çalıştığınız API bulunamadı. Excel’in daha yeni bir versiyonunda mevcut olabilir. Lütfen şu belgeye başvurun: \"https://docs.microsoft.com/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets\".",
            "date": "2023-02-28T20:00:33",
            "request-id": "
            "client-request-id": "***"
        }
    }
}

Secondly, when I want to transfer the successful request in explorer to the code, the patch method does not appear. There is no patch method for update with item at parameter.

graphClient.users(oneDriveProperties.getUserId())           
           .drive()
           .items(oneDriveProperties.getWorkbookId())
           .workbook()
           .tables(oneDriveProperties.getWorkbookTableName())
           .rows()
           .itemAt(WorkbookTableRowItemAtParameterSet.newBuilder().withIndex(rowIndex).build())
           .buildRequest();
           // .send(HttpMethod.PATCH, workbookTableRow);
           // .patch(workbookTableRow);

How can I update this row data? How can I update even by giving range?

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. HarmeetSingh7172 4,826 Reputation points
    2023-03-22T23:40:26.6433333+00:00

    Hello Tugce Avsar,

    Thanks for reaching out!

    I'm able to replicate the error message which you are getting after executing the below Graph endpoint.

    PATCH https://graph.microsoft.com/v1.0/users/{userId}/drive/items/{itemId}/workbook/tables/{tableName}/rows/itemAt(index=2) 
    
    Content-type: application/json
    
    {
      "values": "values-value"
    }
    

    The other way to update table rows via itemAt parameter is not documented in official MS documentation, hence, the patch method is not appearing.

    I would recommend you raise a support case with Microsoft Graph, a Support Engineer will be able to assist you better. You can raise support ticket from http://aad.portal.azure.com/ or https://admin.microsoft.com/#/support/requests.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.