How to download file fromsharepoint using api? - Microsoft Q&A (2024)

Share via

How to download file fromsharepoint using api? - Microsoft Q&A (1)

Ritvik Johar 21Reputation points

2022-11-08T17:07:49.797+00:00

Hi,

I am trying to download files from sharepoint, I have been able to get to the desired folder using https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/items/{item-id}/ but cannot view the files.

Microsoft Graph

Microsoft Graph

A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.

11,188 questions

SharePoint Development

SharePoint Development

SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.

2,773 questions

Sign in to follow

0{count} votes

  1. How to download file fromsharepoint using api? - Microsoft Q&A (2)

    Serkar Aydin 31Reputation points

    2023-03-25T16:39:47.97+00:00

    Hi Johar,

    if you want to download a single file, you can use the

    URI

    "https://graph.microsoft.com/v1.0/drives/$DriveID/items/root:/<filename>" 

    With that you will get a response containing an attribute @microsoft.graph.downloadUrl

    If you invoke a webrequest with outfile, you will be able to download the single file.

    I wrote two articles for that purpose

    How To Download Files From SharePoint Using Graph API (PowerShell): https://sposcripts.com/how-to-download-files-to-from-sharepoint-graph/

    If you want to download a whole SharePoint Library (recursive with sub folders):

    https://sposcripts.com/how-to-download-a-sharepoint-library-using-graph/

    If the answer helps, kindly mark the answer as helpful

Sign in to comment

Accepted answer

  1. How to download file fromsharepoint using api? - Microsoft Q&A (3)

    Srinivasa Rao Darna 6,706Reputation points Microsoft Vendor

    2022-11-09T08:11:11.1+00:00

    Hello @Ritvik Johar ,

    If you are looking to download file uploaded in document library referred as driveItem driveitem-get-content.

    GET /sites/{site-id}/drives/{drive-id}/root:/{path-relative-to-root}:/content GET /sites/{site-id}/drives/{drive-id}/items/{item-id}/content 

    If you are looking to download file uploaded to a list item referred itemAttachment, currently Microsoft Graph doesn't have support for list item attachments, you can upvote feature requested submitted by other Graph users.
    Add support for SharePoint List Item Attachments in Graph
    Ability to attach files to list items using Graph API.

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

    1. How to download file fromsharepoint using api? - Microsoft Q&A (4)

      Ritvik Johar 21Reputation points

      2022-11-10T20:09:45.917+00:00

      Hi @Srinivasa Rao Darna ,

      I am able to view the content on postman but is there a way to download the as well.

    2. How to download file fromsharepoint using api? - Microsoft Q&A (5)

      Srinivasa Rao Darna 6,706Reputation points Microsoft Vendor

      2022-11-11T08:29:08.857+00:00

      Hello @Ritvik Johar ,

      With GET /sites/{site-id}/drive/root:/{path-relative-to-root}:/content from below SPO library.
      Using Postman Save Response >> Save to a file able to download the same.

      How to download file fromsharepoint using api? - Microsoft Q&A (6)

      How to download file fromsharepoint using api? - Microsoft Q&A (7)

      Hope this helps!

    Sign in to comment

2 additional answers

Sort by: Most helpful

Most helpful Newest Oldest

  1. How to download file fromsharepoint using api? - Microsoft Q&A (8)

    Rob Windsor 1,961Reputation points

    2022-11-09T07:14:47.023+00:00

    Here's a link to the documentation on downloading files using Microsoft Graph

    Download the contents of a DriveItem

    Also, these Microsoft Learn training modules cover how to download files using Microsoft Graph and C# or JavaScript.

    Access Files with Microsoft Graph (using C#)

    Download and upload files in a JavaScript app with Microsoft Graph

    The examples in the Microsoft Learn training modules work with files in OneDrive instead of SharePoint. There are a few ways to build a URL to get a SharePoint file in Microsoft Graph, I'll show you one of them.

    Let's say you have files in a library at https://m365x214355.sharepoint.com/sites/contoso/Documents, you can get the items in that library using Microsoft Graph by making a GET request to https://graph.microsoft.com/v1.0/sites/M365x214355.sharepoint.com:/sites/contoso:/lists/Documents/items. The general format of that request is https://graph.microsoft.com/v1.0/sites/{hostname}:{server-relative-path}:/lists/{list-name}/items.

    You can then get the specific file by appending its list item Id. For example, https://graph.microsoft.com/v1.0/sites/M365x214355.sharepoint.com:/sites/contoso:/lists/Documents/items/2.

    How to download file fromsharepoint using api? - Microsoft Q&A (9)

    This gives you a List Item resource, but you need a Drive Item resource to be able to download the file. Fortunately, you can easily get the Drive Item by appending /driveitem to the URL. For example, https://graph.microsoft.com/v1.0/sites/M365x214355.sharepoint.com:/sites/contoso:/lists/Documents/items/2/driveitem.

    How to download file fromsharepoint using api? - Microsoft Q&A (10)

    Finally, you can get the content for the file by appending /content to the URL. For example, https://graph.microsoft.com/v1.0/sites/M365x214355.sharepoint.com:/sites/contoso:/lists/Documents/items/2/driveitem/content

    Hopefully you'll be able to combine this technique to address the Drive Item resource for a file in SharePoint and the examples in the Microsoft Learn training modules to be able to download files.

    1. How to download file fromsharepoint using api? - Microsoft Q&A (11)

      Deepank Kartikey 1Reputation point

      2022-11-09T19:05:05.523+00:00

      @Rob Windsor
      I am collaborator with Ritvik working on the same project.

      Can you tell, how can one access files located within folder inside a driveitem?

      example- file to be downloaded is present at /sites/contoso/parentFolder/childFolder/file_to_access.xls

    Sign in to comment

  2. How to download file fromsharepoint using api? - Microsoft Q&A (12)

    RaytheonXie_MSFT 33,176Reputation points Microsoft Vendor

    2022-11-09T06:31:02.23+00:00

    Hi @Ritvik Johar
    You can use following api to download file.

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

    I have found a similar issue for you to reference
    https://learn.microsoft.com/en-us/answers/questions/601256/downloading-docuemtn-form-sharepoint-documents-usi.html

    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. How to download file fromsharepoint using api? - Microsoft Q&A (13)

      Ritvik Johar 21Reputation points

      2022-11-10T20:09:02.307+00:00

      Hi @RaytheonXie_MSFT ,

      I am able to view the content on postman but is there a way to download the as well.

    Sign in to comment

Sign in to answer

How to download file fromsharepoint using api? - Microsoft Q&A (2024)
Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5533

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.