Get SharePoint folders and docs using Microsoft Graph API

microsoft graph api sharepoint example
microsoft graph api upload file to sharepoint
microsoft graph api download sharepoint file
microsoft graph explorer
microsoft graph api onedrive
microsoft graph api upload file c#
microsoft graph sharepoint list items
sharepoint graph

I'm trying to get the folders and documents from a SharePoint document library using Microsoft Graph API.

If I do a GET request for https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/, I get this back:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
    "value":[
        {
            "createdDateTime": "2019-09-05T07:09:49Z",
            "description": "",
            "id": "b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX",
            "lastModifiedDateTime": "2019-09-05T07:09:49Z",
            "name": "Documents",
            "webUrl": "https://mysite.sharepoint.com/sites/MyDocumentSite/Shared%20Documents",
            "driveType": "documentLibrary",
            "createdBy":{"user":{"displayName": "System Account" }},
            "lastModifiedBy":{"user":{"email": "me@myorganization.org", "id": "73f9990c-5c92-4839-8b13-XXXXXXXXXXXX", "displayName": "John Smith"…},
            "quota":{"deleted": 0, "remaining": 0, "total": 0, "used": 0}
        }
    ]
}

But if I try to access that drive by doing a GET request on that id: https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX, I get a BadRequest error:

{
    "error":{
        "code": "BadRequest",
        "message": "Url specified is invalid.",
        "innerError":{
            "request-id": "7c9eaf61-764f-4d72-abdb-ffa2fe868e90",
            "date": "2019-09-16T19:09:41"
        }
    }
}

Ultimately, I want a way to display all folders and documents from the document library but I can't seem to get past this initial step.

Use the "delta" API: https://docs.microsoft.com/en-us/graph/api/driveitem-delta?view=graph-rest-1.0&tabs=http

The first call will return all the items. (If there is pagination you'll need to call nextLink, until you receive a deltaLink).

You will probably want to use one either GET /sites/{siteId}/drive/root/delta or GET /drives/{drive-id}/root/delta

Working with SharePoint sites in Microsoft Graph, For existing solutions using OneDrive API outside of Microsoft Graph, Getting started. To quickly experiment with Microsoft Graph and accessing files, /drive/​root:/path/to/folder:/children, List children when accessing by  The SharePoint API in Microsoft Graph supports the following core scenarios: Access to SharePoint sites, lists, and drives (document libraries) Read-only support for site resources (no ability to create new sites) Read-write support for lists, listItems, and driveItems; Address resources by SharePoint ID, URL, or relative path

OneDrive and SharePoint in Microsoft Graph, Use the "delta" API: https://docs.microsoft.com/en-us/graph/api/driveitem-delta?​view=graph-rest-1.0&tabs=http. The first call will return all the  The REST API is shared between OneDrive, OneDrive for Business, SharePoint document libraries, and Office Groups, to allow your app the flexibility to read and store content in any of these locations with the same code. These REST APIs are a part of the Microsoft Graph, a common API for Microsoft services.

Once you get the drive id you want to query, use /drives at the root to make your request:

https://graph.microsoft.com/v1.0/drives/<driveId>

Get SharePoint folders and docs using Microsoft Graph API, Prerequisites. Register an Azure AD app and allow the app to have full/read control to SharePoint sites in all site collections without a signed-in user. Refer to the Microsoft Graph permissions reference here. Note down the Application ID(Client ID) and Key(Client Secret). Microsoft Graph is a RESTful web API that enables you to access Microsoft Cloud service resources. In this article, we will go through the requests we have to make in order to access the documents in a SharePoint Document Library.

Microsoft Graph API, He needs to show the file information from a document library. It's always possible using SharePoint REST API, but they are facing a problem for  4/02/2019 MS Graph: Get DriveItem by File Absolute Url Microsoft Graph allows to work with OneDrive files and SharePoint documents using DriveItem resource type. Using this entity you can read information about a file, such as size, content, file type, and so on (here is a link to the resource type documentation).

Retrieve Files and Items from Sharepoint Using Microsoft Graph API, items such as site collections, lists, document libraries and files. SharePoint is your mobile, intelligent intranet. With SharePoint, users can share and manage content, knowledge, and applications to empower teamwork, find information, and collaborate across an organization. You can use the SharePoint REST API in Microsoft Graph to integrate your solutions with SharePoint sites and content.

Using the Graph API with SharePoint, The Microsoft Graph API is the new unified endpoint for developers Unfortunately, I did not find documented samples how to access Excel-files from a SPO site. My target file is stored in the Documents folder with ID  You can use Microsoft Graph to create an app that connects with files across OneDrive, OneDrive for Business, and SharePoint document libraries. With Microsoft Graph, you can build a variety of experiences with files stored in Microsoft 365, from simply storing user documents to complex file-sharing scenarios.

Comments
  • That only seems to work for the default drive on the global site, not the sub-site that my document library lives on. See my URLs in the question.
  • Notice in the URLs in the original question, I'm using /sites/{site-url}:/{subsite-path}:/drives to get my drive list.
  • Should work fine if you use the drive id (without the site id) + delta.