Reputation: 13
I need to get the content of a file (in this case the text written in a notepad file) that's located on a sharepoint site. I have learned this could be done by using Microsoft Graph or the sharepoint API. Because I have previously used Microsoft Graph API's, I would prefer to do so again. I have already tried making HTTP GET requests using the, in my opinion, correct API's, but they somehow keep failing me.
My experience with API's was very little two weeks ago, but has grown a lot since then. I'm using Azure's Logic Apps to make the API request by using the HTTP connector. I added the required API application permissions for Microsoft Graph API and Sharepoint API (Sites.ReadAll) to the App Registration I made in Azure Active Directory. The first request I make is the request for an Access Token. This request works perfectly fine and I get an access token. Then I use this access token to try and get the file content from a certain file on the sharepoint site. The request URL I blacked out for privacy reasons, but it's comparable to
https://graph.microsoft.com/v1.0/sites/{siteId}/drive/root:/{item-path}
For example:
https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com,kkkkkkkkd-dsdksdkspd-ds5sd65d544,hidzijij-ksdoqkdsnns88/drive/root:/Shared%20Documents/test1/test2/testfile.txt
And the output I get is always (I have been looking for possible solutions to whatever mistake I am making for about 10 hours now) the following:
As I said before, I have tried different API's following Microsoft's Documentation, for both Graph API and sharepoint API about this (https://learn.microsoft.com/en-us/graph/api/resources/onedrive?view=graph-rest-1.0), but none seem to work. I have no idea what mistake I'm making, so if anybody has a clue, I would be very glad if you could help! :D
PS: The sharepoint site with it's folders is made by me, with the same Microsoft account as the one that I'm logged in with on Azure, so that can't be the problem.
Upvotes: 1
Views: 1502
Reputation: 1804
I've done something similar a while back.
The URI template I used was:
https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{drive-item-id}/content
It should be a GET
request obviously, and don't forget the bearer token in Authorization
header.
Please note that in your request you haven't specified the /content
what means you will get the file metadata rather than it's bytes.
In addition, note that in Microsoft Graph Docs it seems that in order to download a file from SharePoint site you will have to know its drive-item-id (using path instead isn't mentioned there as a valid option so I'm not sure if it's possible..)
Good luck
Upvotes: 0
Reputation: 1476
When using Logic Apps it's a lot easier to connect to SharePoint using the provided connector: https://learn.microsoft.com/en-us/azure/connectors/connectors-create-api-sharepoint
Regarding the Graph API, it looks like you might need to use a workaround: Microsoft Graph download file content returns 404
Upvotes: 1