Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the siteId of the current site with Microsoft Graph API?

From the documentation, I can't find any ways to get the siteId of the site where I put the webpart in.

For example,

My current site is: https://{hostname}/sites/main1 <-- NOT root site, but I want to get this siteId

and I test my webpart here: https://{hostname}/sites/main1/_layouts/15/workbench.aspx

How can I achieve this? From the documentation,

A site is addressed be a unique identifier which is a composite ID of the following values:

Site collection hostname (contoso.sharepoint.com)

Site collection unique ID (guid)

Site unique ID (guid)

I can get the hostname easily by using location.hostname (Yes, I am using JavaScript + React to build my webpart) but how to get the site-id easily with Graph API?

like image 414
PCHC Avatar asked Jul 31 '17 01:07

PCHC


People also ask

How do I find the site ID?

Go to Administration (click on the gear icon in the top right of the screen). Click on the Measurables(or Websites) > Manage page. You will find a list of all websites on this page. The website ID is on the left of the table listing all websites directly below the website name.

How do I get data from Microsoft Graph API?

Graph Explorer is a web-based tool that you can use to build and test requests using Microsoft Graph APIs. You can access Graph Explorer at: https://developer.microsoft.com/graph/graph-explorer. You can either access demo data without signing in, or you can sign in to a tenant of your own.

How do you get a SharePoint list data from a graph API?

GraphServiceClient graphClient = new GraphServiceClient( authProvider ); var queryOptions = new List<QueryOption>() { new QueryOption("expand", "fields(select=Name,Color,Quantity)") }; var items = await graphClient. Sites["{site-id}"]. Lists["{list-id}"].

How do I find SharePoint Online List ID?

You can find the ListId by navigating to the SharePoint list, and then copying the URL, and finding the ID. Open SharePoint, and navigate to the list that contains your workflow. Click Edit this list, and then click List in the ribbon.


1 Answers

Try this: https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{path}?$select=id For example: https://graph.microsoft.com/v1.0/sites/cie493742.sharepoint.com:/sites/Contoso/Operations/Manufacturing?$select=id (this one you can try on the Graph Explorer.

What you get back in the id is in this format:

{hostname},{spsite.id},{spweb.id}

For more info here is the link to the docs: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/site_get

like image 153
Yina - MSFT Avatar answered Sep 21 '22 17:09

Yina - MSFT