2
votes

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://docs.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0 https://docs.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

1 Answers

6
votes

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