0

My goal is to read the data inside an Excel at azure with some get request. I am trying to get the JSON contain the information form one of my Excel files. I am using the "Excel: used range in worksheet", it can be found in the page "https://developer.microsoft.com/en-us/graph/graph-explorer". In the get query area it says the query is: https://graph.microsoft.com/v1.0/me/drive/items/{drive-item-id}/workbook/worksheets('Sheet1')/usedRange. After changing the {drive-item-id} and the Sheet1 for correct values it gives me an error or authentication:

{"error":{"code":"InvalidAuthenticationToken","message":"Access token is empty.","innerError":{"date":"2021-06-09T16:26:24","request-id":"60912689-40d7-4f84-ba3b-d2350d121044","client-request-id":"60912689-40d7-4f84-ba3b-d2350d121044"}}}

Is it possible to just add the access token to it and get all the data from the file? For example: https://graph.microsoft.com/v1.0/me/drive/items/{drive-item-id}/workbook/worksheets('Sheet1')/usedRange?token=12345678

Hygison Brandao
  • 590
  • 1
  • 4
  • 16

1 Answers1

0

It is not possible to add the access token directly to the request URL, you need to add it to the request header as Authorization:Bearer <access token>(don't miss the space) when you call the API.

You can also call the API in the graph explorer, in it don't need to add the token manually, just sign the explorer and click Modify permissions to add Files.ReadWrite delegated permission, then you can call the API.

enter image description here

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • When I open that it is ok, but I mean I need to open with a script, using or php or javascript. So that is why I cannot go to that page every time, but I want to perform the actions that exist in that page – Hygison Brandao Jun 10 '21 at 05:16
  • @HygisonBrandao Of course, you can, just add the token to the request header as I mentioned. – Joy Wang Jun 10 '21 at 05:44
  • Could you tell me the link then? like, what should I change here: https://graph.microsoft.com/v1.0/me/drive/items/{drive-item-id}/workbook/worksheets('Sheet1')/usedRange?token=12345678 – Hygison Brandao Jun 10 '21 at 07:00
  • @HygisonBrandao Just follow this [answer](https://stackoverflow.com/questions/36975619/how-to-call-a-rest-web-service-api-from-javascript) to make the API call, add `'Authorization': 'Bearer '` to the headers, also remove `?token=12345678` in the url. – Joy Wang Jun 10 '21 at 07:05