I am trying to download a word document file named Test.docx located in Sharepoint Document Library from within a Visio File macro referring to the Microsoft documentation at https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http
I am able to get my site ID and Item ID ending up to the below URL,
https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{item-id}
Since I want to download the file content in binary and save it locally, I add "content" to the url as below,
https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{item-id}/content
My code looks as below in VBA environment for the client as below with an active Access Token,
myURL=https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{item-id}/content
Set winHttpReq = New XMLHTTP60
winHttpReq.Open "GET", myURL
winHttpReq.setRequestHeader "Authorization", "Bearer " & AccessToken
winHttpReq.send
I am getting an error as "Access is denied." at the line winHttpReq.send and control exits out of the function.
Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite are the permissions already given for the API access.
Also, I did another call fetching the "@microsoft.graph.downloadUrl" download URL but I did not see any binary content in the response.
My questions are,
- Is my approach correct?
- I need the file binary data to be downloaded using graph API but adding /content to the URL gives this error. How can I get the file using API?
- Where can I fetch the binary content from the response to the url of "@microsoft.graph.downloadUrl" of the file to download and save the file locally?
- Is there any other approach to download a file using the graph API that will work in VBA environment?