2

As stated in the title, I've been trying to use the Microsoft Graph API to pull an Excel workbook from our company's Sharepoint site. I am able to retrieve the metadata for the file, but when I add the /workbook/ segment to the URL, I receive the below error:

{
  "error": {
    "code": "BadRequest",
    "message": "Resource not found for the segment 'workbook'.",
    "innerError": {
      "request-id": "bf41e41a-bc01-4c3b-b1d7-3125c4d48124",
      "date": "2019-04-10T16:29:07"
    }
  }
}

Here is what the successful call getting the file metadata looks like:

https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/items/273

And here is the call I am making which returns the above error:

https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/items/273/workbook/

I was able to find this stackoverflow post discussing a similar error, however that was a couple of years ago, apparently using a beta version of the Graph API, and I was not able to get any farther using suggestions from that post. Get workbook from sharepoint site using microsoft graph beta

I am building my request URL based on reading these two Microsoft docs: https://learn.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0 https://learn.microsoft.com/en-us/graph/api/resources/excel?view=graph-rest-1.0

I don't think it's relevant, but I'm using C# and building the requests with Restsharp.

Does anyone have any insight on this?
Thanks!

1 Answer 1

7

You can't use /workbook against a ListItem, it can only be used with a DriveItem.

In order to do that, you'll need to first obtain the DriveItem associated with the ListItem:

/v1.0/sites/{siteid}/lists/{listid}/items/273/driveitem/workbook
Sign up to request clarification or add additional context in comments.

3 Comments

That works! Where did you go to learn that? The "Working with Excel in Microsoft Graph" doc doesn't specify that at all, and to my eyes indicates that a file could be accessed as I was attempting to. learn.microsoft.com/en-us/graph/api/resources/…
I'm afraid it came years of experience being neck-deep in Graph metadata and nuances. That said, I completely agree: github.com/microsoftgraph/microsoft-graph-docs/issues/4369
I get data for /driveitem/ but for /driveitem/workbook I get "innerError": { "code": "FileOpenNotFound", "message": "We couldn't find the file you wanted." }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.