What are the different ways to get SharePoint Site Collection using Microsoft Graph

Published by Shantha Kumar on

Microsoft Graph API has a single endpoint, which allow us to access any data across Office 365 environment by using different parameters. This post explores the different ways of retrieving the Site Collection using MS Graph API from Microsoft Graph Explorer.

  • Navigate to Microsoft Graph Explorer
  • Select the GET method from Request drop down
  • Select the version as v1.0 or beta
  • Enter the API endpoint to the request textbox and then click Run Query button to run the Graph request.
  • Use the Permissions section to agree the scopes required for accessing the API.

To read site collection related information, we must agree Site.Read.All permission scope

We can access the site collection using three different ways in Microsoft Graph API,

  • By using root
  • By using Site ID
  • By using Site server relative URL.
  • By using Group ID

Get SharePoint site collection by using ‘root’

root parameter next to the sites, denotes the default and top level site collection

https://graph.microsoft.com/v1.0/sites/root

 

Get SharePoint site collection by using Site ID

If we have the unique id of the site collection, we can retrieve it by specifying site id next to sites,

https:// graph.microsoft.com/v1.0/sites/<siteid>

Example

https:// graph.microsoft.com/v1.0/sites/298ada92-042b-4bf3-ae87-3b207baf17dc

 

Get SharePoint site collection by using server relative url

https://graph.microsoft.com/v1.0/sites/<host>:<server relative url>

Example

https://graph.microsoft.com/v1.0/sites/ktsdemo.sharepoint.com:/sites/demos

Get SharePoint site collection using Group ID

If the SharePoint site collection is created based on Office 365 group, we can use the below endpoint to retrieve the top level site.

https:// graph.microsoft.com/v1.0/groups/<group-id>/sites/root

Example

https:// graph.microsoft.com/v1.0/groups/ 298ada92-042b-4bf3-ae87-3b207baf17dc/sites/root


Leave a Reply

Your email address will not be published. Required fields are marked *