Best way of downloading Files off of SharePoint Online through Graph API?

Adz 286 Reputation points
2021-12-17T09:49:35.027+00:00

I have a requirement where I need to get all uploaded/attached files off of a SharePoint Online site(s). Which is the recommended way to do this?

Currently I'm accessing the metadata for a Sites files through

GET /sites/{id}/drives
GET /drives/{drive-id}/items/root/children
GET /drives/{drive-id}/items/{item-id}/children

and downloading the contents through

GET /drives/{drive-id}/items/{item-id}/content

and so on.

Was just wondering if there's anything I'm missing or if there's a "better" way of doing this please?

Microsoft Security | Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. Zehui Yao_MSFT 5,876 Reputation points
    2021-12-20T08:29:16.47+00:00

    Hello, @Adz ,
    of course, you can use this API point to download items files, which is the officially recommended method. For more information, you can refer to this document, hope that may help you.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. JanardhanaVedham-MSFT 3,566 Reputation points
    2021-12-21T19:28:59.837+00:00

    Hi @Adz ,

    I tested the below Graph API endpoints in Graph Explorer and Postman to download a specific file from SharePoint document library. You can use any of the below Graph APIs and also refer/use other additional APIs which are provided in this documenation as per your requirement:

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem/content  
    

    Example:

    159386-downloadfile-driveitem.jpg

    GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root:/{item-path}  
    

    Here {item-path} can be /{file-name}
    You can use the field “@microsoft.graph.downloadUrl” in order to download the file in your application.

    Example:
    159378-downloadfile-filename-or-path.jpg

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have futrther questions about this answer, please click "Comment".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.