2

I'm trying to find a way in Sharepoint Graph API how download file in Document library that are not listed as drive (Site Pages and others). If I enumerating lists, I see "Site Pages" in lists:

https://graph.microsoft.com/v1.0/sites/<site id>/lists

I even can enumerate item in list :

https://graph.microsoft.com/v1.0/sites/<site id>/lists/<list id>/items

But I can't find a way to get a content (download) those items (files). All available url to download file (get content) are next:

GET /drives/{drive-id}/items/{item-id}/content
GET /groups/{group-id}/drive/items/{item-id}/content
GET /me/drive/root:/{item-path}:/content
GET /me/drive/items/{item-id}/content
GET /sites/{siteId}/drive/items/{item-id}/content
GET /users/{userId}/drive/items/{item-id}/content

Doesn't provides an ability to get the content. I can't find a way to get drive id for list, and there's no url to get content from list (even if it's documents library).

Please advise. Thanks

SlavaG
  • 518
  • 8
  • 28

2 Answers2

3

You can call the following endpoints to retrieve:

  1. all document libraries on a site
  2. items in a document library (from root)
  3. download the content of an item

This may not be the most efficient set of queries but I successfully tested in my lab tenant.

  1. https://graph.microsoft.com/(version)/sites/(site-id)/drives

  2. https://graph.microsoft.com/(version)/sites/(site-id)/drive/(drive-id)/root/children

  3. https://graph.microsoft.com/(version)/sites/(site-id)/drive/(drive-id)/items/(item-id)/content

  • Note that I specified site-id as (hostname),(site-guid),(web-guid) rather than using relative URL syntax. I've seen small differences between the two in past. – Brian T. Jackett MSFT May 09 '20 at 16:10
  • Thanks, what's the difference that you saw? – SlavaG May 09 '20 at 20:18
  • Here is a question with an example. Getting drive / file information yields a 400 Bad Request with relative URL syntax but works fine with GUIDs syntax. [https://stackoverflow.com/questions/61597024/issues-getting-drive-information-when-using-the-graph-api-with-a-server-relative](https://stackoverflow.com/questions/61597024/issues-getting-drive-information-when-using-the-graph-api-with-a-server-relative) – Brian T. Jackett MSFT May 10 '20 at 11:39
  • Thanks Brian, I see another strange issue, don't know to what it can be related, maybe you know the answer :) : https://stackoverflow.com/questions/61678111/sharepoint-graph-api-strange-behaviour-while-trying-to-get-download-link-for-a-f – SlavaG May 10 '20 at 11:49
  • Thanks Brian! This three-step approach was very valuable for me. In Graph API docs, there is nothing about downloading files under Sites nor Lists. I didn't realize I had to look for Drives and Items. – Jari Turkia Sep 06 '22 at 08:41
-1

The drive resource represents a user's OneDrive or a document library in SharePoint. while site page is a page library, not document library, this is why it's not returned in drive request.

We suggest you get the file using SharePoint Rest API.

Baker_Kong
  • 1,739
  • 1
  • 4
  • 9
  • Thanks. But there's an issue with REST : https://github.com/SharePoint/sp-dev-docs/issues/5247 and https://stackoverflow.com/questions/59737754/sharepoint-rest-api-returns-incomplete-content-of-file-during-downloading - they are suggesting to use Graph API, so it's kind a ping pong. – SlavaG Apr 30 '20 at 12:32