Graph API is a powerful tool that allows developers to interact with various Microsoft services, including SharePoint. With Graph API, it's easy to upload files to a SharePoint site. Today, I would like to share my knowledge on how to upload a file to a SharePoint site using Graph API via Postman. Postman is a popular tool for testing and managing APIs, developers can easily test the Graph API's file upload functionality and ensure that the system is working as expected.
The process of uploading a file to SharePoint via Graph API involves sending a request to the SharePoint Graph API endpoint. Before sending a request to the SharePoint Graph API endpoint, the developer must authenticate and authorize the request using Microsoft's authentication mechanism based on OAuth 2.0 protocol. This involves obtaining an access token that allows the developer to access the required SharePoint site.
Overall, the combination of Graph API, SharePoint, and Postman can be a powerful tool for businesses looking to streamline their document management processes and improve collaboration among team members.
1. Registering your App in Azure Portal
- Search and select App Registration.
- Name for your App and Click Register.
- The system will exhibit the following screen.
- Add Redirect URI
- Add Redirect URIS as shown below.
- Select Certificate & secrets from left hand Menu and then click New client Secret as shown below.
- Enter the Description and select Expire duration, then click on Add.
- Now we shall add permissions to the App.
Select API permissions from left hand side navigation menu and then select graph API.
- You should select the Application Permission and select Site.ReadWrite.All and click add permission.
- In my Case I should request the permission from Admin, if you’re the admin then you can grant permission by clicking Grant Admin Content.
2. Uploading a file Via Postman.
- In this Step We are generating the access token via Postman this can be use between 60 to 90 minutes. We have one header “Content-Type” and for the body we have four parameters.
- In this step we going to get the SharePoint Site ID through Get method by using the barer token, with below mentioned graph API Call https://graph.microsoft.com/v1.0/sites/{{TenantName}}.sharepoint.com.:/sites/SiteName I’m using the SharePoint site name which I have shown below.
- In the Response message you can find the ID with comma separated strings , there you should get the Second string which is highlighted above.
- In this Step we will find out how to get the List ID’s. we should use get method with bearer Token and following Graph API https://graph.microsoft.com/v1.0/sites/{{SiteID}}/lists
- In this Step we will find out how to Get the Drive ID. This is a folder path in your SharePoint. To achieve this We should use get method with bear Token and the following Graph API
https://graph.microsoft.com/v1.0/sites/{{SiteID}} /Drives.
- Now we are going to list the items what is exist in the folder path to do that we should use the following API Call https://graph.microsoft.com/v1.0/Drives/{{DriveID}}/root:/ERP-CRM Enhancement (ERP Dev):/Children.
- Now we can upload a File. In this step we should use Put Method with Bearer Token and following API.
https://graph.microsoft.com/v1.0/drives/{{DriveID}}/root:/ERP-CRM Enhancement (ERP Dev)/BC.png:/content.
- Select a file and click send.
- We can see the file what I have uploaded.
Hope you find it useful.
Thank you.
Comments