3
votes

I'm looking to connect to the Microsoft Graph API and interact with a small Excel workbook on my OneDrive.

I am able to successfully authorize & connect to OneDrive through the Graph API, query my personal OneDrive contents, and I can even find the .xlsx workbook and grab its ID. A GET request to this endpoint is successful:

https://graph.microsoft.com/v1.0/me/drive/recent

The response to that above GET request includes (some data omitted):

{createdDateTime: "2017-12-13T04:24:57Z", lastModifiedDateTime: "2017-12-13T04:26:09Z"}
id:"{id}"
name:"transactions.xlsx"

However, connecting to this "transactions.xlsx" workbook through a graph API call seems to struggle in my web application. For example a GET request here:

https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/worksheets('Sheet1')/usedRange

returns workbook data successfully through the Graph Explorer. But merely copying + pasting that API call into my app then fails with:

{
  "error": {
    "code": "itemNotFound",
    "message": "The resource could not be found.",
    "innerError": {
      "request-id": "7716493f-cc32-413e-b4fa-5855df7ad181",
      "date": "2017-12-13T14:54:43"
    }
  }
}

What am I missing about Graph API calls that is allowing my OneDrive queries to pass but the Excel queries to claim item not found?

This is a business Microsoft Graph/O365 account

2
How are you obtaining the Access Token? Which scopes have you requested and which OAUTH grant flow are you using?Marc LaFleur
I am using this code sample that I believe connects via Oauth 2.0 github.com/microsoftgraph/ruby-connect-rest-sample. Unsure what scopes I have requested - I can look into that further.Bryan Knouse
In your app, does the plain file GET operation (not with /workbook but on /items/{id}) work? It sounds like the file itself is not resolving. Could you try and update the results?Sudhi Ramamurthy
Sudhi, those operations work on the graph explorer. Tried in app and same error quoted in the above question.Bryan Knouse
Are you logging in with the same credentials in Graph Explorer and your application?Marc LaFleur

2 Answers

0
votes

Could you try with one of the getting started projects for Excel REST to see if you can get desired result? https://github.com/microsoftgraph?utf8=%E2%9C%93&q=excelstarter.

0
votes

The response you are displaying for GET /me/drive/recent is quite limited. Is there any entry for remoteItem on your results?

If that is the case you need to use a different URL to get the transaction.xlsx file.

GET /drives/{remoteItem-driveId}/items/{remoteItem-id}

From: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/drive_recent#remarks

If that is not the case, you can also use the following request to find out your folder structure:

GET /me/drive/root/children

With the results of the above query, you can then use this to retrieve the contents of the folders:

GET /me/drive/items/{item-id}/children

Once you know the exact location you can use the following to retrieve your workbook:

GET /me/drive/root:/{item-path}

Obviously if you already know the path you can go directly to the last step :-)