Use the ID in a SharePoint Link to download the file with MS Graph Request

Thierry S 0 Reputation points
2024-11-29T10:58:12.0166667+00:00

Hello, I have a sharepoint link to a file like below, and I would like to download the file, using MS GRAPH request :

https://myfirm.sharepoint.com/:x:/r/sites/Team-Sharepoint-Test/Shared%20Documents/General/Test%20folder/MyFile.xlsm?d=wc0d04cb7381c4374bc498aed63748627&csf=1&web=1&e=4bkpKu

I can do it by using the relative path of the file, but I would like to use the ID (In my case : wc0d04cb7381c4374bc498aed63748627). How can I do it ?

As i understand, I can use a request like below, but it doesn't work with this ID, right ? As I understand, there is a sharepoint ID and a MS graph ID ?

Who can help me ? Thanks for your support !

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

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,443 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hitesh Pachipulusu - MSFT 3,390 Reputation points Microsoft Vendor
    2024-11-29T13:04:01.4533333+00:00

    Hello Thierry S,

    Thank you for contacting Microsoft Support!

    To download a file from SharePoint using the with Microsoft Graph, you can indeed use the GET /drives/{drive-id}/items/{item-id}/content endpoint.

    Here are the steps you can follow:

    1. Get the SharePoint Site ID: First, you need to get the SharePoint Site ID. You can do this by using the following request:
         GET https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{sitename}?$select=id
      
    2. Get the Drive ID: Then you need to get the drive ID of the SharePoint document library. You can do this by using the following request:
         GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives
      
      This will return a list of drives, and you can find the drive ID for the document library where your file is located.
    3. Get the Item ID: Once you have the drive ID, you can get the item ID using the SharePoint-specific ID. Use the following request:
         GET https://graph.microsoft.com/v1.0/drives/{drive-id}/items/
      
    4. Download the File: Finally, use the Microsoft Graph API to download the file:
         GET https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/content
      

    Hope this helps.

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

    0 comments No comments

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.