Table of contents

Weâll be using Postman to demonstrate how to get SharePoint files via the API.
SharePoint is a collaboration and document management platform that many enterprise organizations use to organize, share, and access files. There are many use cases for the SharePoint REST API, but the one of the most common requests we see is how to GET all files from the API.
In order to access SharePointâs API, youâll first need a sandbox SharePoint account and an OAuth application. The main way to get both of these is to apply for a Microsoft Developer account here.
You may be prompted to select the products you are interested in. If available, select the options related to SharePoint, OneDrive, and Microsoft Graph.
Your sandbox account will renew every 90 days if you actively use it.
Youâll need to populate your SharePoint sandbox account with data. To do this:
1. Within your SharePoint account, create a site. (Either a Team or Communication site will work.)

2. Once your new site is created, navigate to Documents, and click + New to add new files and folders!

To create an OAuth app, navigate to your developer account https://portal.azure.com/#home, then navigate to Azure Active Directory > App Registrations > + New Registration to create a new OAuth app. If youâre using Postman to test the integration, add the Postman URL as your redirect URI (https://oauth.pstmn.io/v1/browser-callback).

Youâll see an app created, with a provided client ID.

The last step is to create a client secret. To do so, click Client credentials > Client secrets > + New client secret.

Now youâre fully set up!
https://www.merge.dev/blog/sharepoint-api-python?blog-related=image
Oauth:
authorize URL: https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize
token URL: https://login.microsoftonline.com/organizations/oauth2/v2.0/tokenâ
scopes: âoffline_access https://graph.microsoft.com/.defaultâ
Copy and paste your client id from your OAuth appâs âApplication (client) IDâ and your client secret from your OAuth appâs âClient Secret > Valueâ.


In Postman, once youâve entered all the params, click âGet Access Tokenâ. This will take you through the OAuth flow, and at the end, you should be able see an âAuthentication completeâ screen. Use the access token provided by this flow, which Postman will automatically add as auth headers for your subsequent API requests!
Related: How to access your API key in SharePoint
1. First, access your sites, using the following command:
SharePoint is organized by sites, and sites have their own files & folders. The âsearch=*â query param allows you to pull all sites.

2. Second, choose a site to pull drives from. Using the siteâs id, you can then make the following command to get the drives. Usually, there is one drive per site.

3. Lastly, youâll want to get the <code class="blog_inline-code">DriveItems</code> under these Drives. <code class="blog_inline-code">DriveItems</code> is how Microsoft represents its files and folders. Using the <code class="blog_inline-code">drive id</code> and <code class="blog_inline-code">site id</code>, call the following to get the driveâs files and folders.
Additionally, you can use the select query param to view only the fields you want to see.

4. The above endpoint only surfaces the <code class="blog_inline-code">DriveItems</code> in the root directory of the specified drive. To pull deeper items within a <code class="blog_inline-code">DriveItems</code> that is a folder, use the <code class="blog_inline-code">DriveItems</code> id and call the following.

There are a couple of points to consider when turning this simple proof of concept into a production-level integration:
This article showed you how to GET all files from SharePoint.
As your needs for integrations grow, Merge connects your product to hundreds of integrations with one single API in HR, recruiting, accounting, ticketing, CRM and marketing automation. As with all of Mergeâs Unified APIs, one API connection is enough to offer your users integrations to all File Storage platforms including Sharepoint, OneDrive, Dropbox, Box, Google Drive, and more.
You can schedule a demo with one Merge's integration experts to learn more.
Learn how Merge can help you integrate your product with SharePointâand many other file storage applicationsâthrough a single unified API.