1

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

HTTP get driveItem request

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:

HTTP request output

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.

Felix Bing
  • 13
  • 8

2 Answers2

1

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

bvpb
  • 1,416
  • 22
  • 31
  • yes, I would love to use the SharePoint connector, but I'm building a Logic App for a company as part of my internship, and I was told there should not have to be made any kind of changes in the Logic App itself. So the SharePoint connector is not an option here as this only allows for a connection to be set up inside the Logic App. I need to request all the information I need - using API - from a template that can be easily filled in by any user within the company. I will have a look at the second link you included, and leave a reply if it helped me out! – Felix Bing Mar 06 '20 at 14:28
0

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

Noam
  • 1,640
  • 4
  • 26
  • 55
  • I tried this but I got to the same result: 'The resource could not be found'. I'm starting to think it's a permission related problem (perhaps the fact that I'm using application permissions instead of delegated permissions?). Anyhow, I've got some time before my due date so I'll guess I'll figure it out someday ;) – Felix Bing Mar 09 '20 at 15:11
  • I used application permission as well so I don't think that's the issue. Good luck anyway. – Noam Mar 09 '20 at 15:27