Connect to SharePoint Online Site with Graph API using Post man
Connect to SharePoint Online Site with Graph API using Azure App Registration with Graph API Sites.Selected Permissions, and test it with Post man.
Create Azure App Registration with Sites.FullControl.All permissions. This App Registration is not for connecting to a SharePoint online site, but it is acted like an admin app which can be used to provide Write access to another Registered App in Azure AD. This is the most important task, please don't skip it.
To provide permissions for your SharePoint site using the Sites.Selected
permission, follow these steps:
Register an Azure AD App:
- Go to the Azure portal and register a new application, Name it as "Admin App"
- Note the Application (client) ID and Directory (tenant) ID.
Grant API Permissions:
- In the Azure portal, navigate to your registered app.
- Go to API permissions and add the
Sites.FullControl.All
permission under Microsoft Graph. - Click Grant admin consent for the permission.
Generate a Client Secret:
- Go to Certificates & secrets in your app registration.
- Create a new client secret and note the value.
Create another Azure App Registration with Sites.Selected permissions, this is the actual app which we use to connect to a SharePoint online site.
To provide permissions for your SharePoint site using the Sites.Selected
permission, follow these steps:
Register an Azure AD App:
- Go to the Azure portal and register a new application, name it as "Client App"
- Note the Application (client) ID and Directory (tenant) ID.
Grant API Permissions:
- In the Azure portal, navigate to your registered app.
- Go to API permissions and add the
Sites.Selected
permission under Microsoft Graph. - Click Grant admin consent for the permission.
Generate a Client Secret:
- Go to Certificates & secrets in your app registration.
- Create a new client secret and note the value.
Open Postman and create a HTTP POST request - For Admin App
address: https://login.microsoftonline.com/{{TenantID}}/oauth2/v2.0/token
client_id:{{ClientID}}
client_secret:{{ClientSecret}}
scope:https://graph.microsoft.com/.default
Content-Type:application/x-www-form-urlencoded
Replace the {{ClientID}} (all flower bracket values) with actual values copied from Azure App Registration for Admin App. This is to get the access token for Admin App, we use this token for granting Read and Write access to Client App.
So far, we have received access token for Admin App, and granted Write access to Client App. Now we will get access token for Client App and try to read the site.
client_id:{{ClientID}}
client_secret:{{ClientSecret}}
Content-Type:application/x-www-form-urlencoded
Click on Send button to post the request and get the access token. You can validate the access token and find the Role as Sites.Selected.
https://graph.microsoft.com/v1.0/sites/{{TenantName}}.sharepoint.com:/sites/{{SiteName}}
Tenant name is your SharePoint URL, site name is the name of the site that you are targeting to access, please replace the above URL with actual values.
Post a Comment