0

I'd like to perform some operations that are only available using the GRAPH Api (adding content from the content type hub for example).

But I'm in a context where I can only perform operations using the SharePoint authenticated context (Power Automate SharePoint connector if it matters). That's why I need to use the SharePoint REST V2 endpoint (/_api/v2.0) and not the standard graph endpoint.

I'm struggling to get the current site ID (graph ID, not SharePoint ID).

How can I retrieve it ?

There are attributes on File object that provide DriveID (VroomDriveID), but I did not find similar attribute for site or web.

I tried:

  • get https://mytenant.sharepoint.com/sites/mysite/_api/v2.0/sites/mytenant.sharepoint.com:/sites/mysite but it does not work
  • get the drive ID first, then trying to reach the drive:
    1. https://mytenant.sharepoint.com/sites/mysite/_api/web/getlist('/sites/mysite/sitepages')/items?$expand=File&$filter=FSObjType eq 0&$top=1&$select=File/VroomItemID,File/VroomDriveID (assuming there's at least one page in the site). This allow me to retrieve one DriveID
    2. then https://mytenant.sharepoint.com/sites/mysite/_api/2.0/drives/<<value of VroomDriveID>>. It also fails
  • search for the current site : https://mytenant.sharepoint.com/sites/mysite/_api/v2.0/sites?search='/sites/mysite'. The query does not fails, but return an empty array
2
  • Which power automate action are you using? Oct 1, 2023 at 2:56
  • I'm using the SharePoint HTTP action to benefits the SharePoint connection (easier that HTTP with AAD auth)
    – Steve B
    Oct 1, 2023 at 9:14

2 Answers 2

1

Your last attempt is almost right! It's $searchnot search.

This URL should return the Graph Site ID:

https://yourtenant.sharepoint.com/sites/yoursite/_api/v2.0/sites?$search=*

Response:

{
    "@odata.context": "https://yourtenant.sharepoint.com/sites/yoursite/_api/v2.0/$metadata#sites",
    "value": [
        {
            "createdDateTime": "2023-09-30T05:41:06Z",
            "id": "yourtenant.sharepoint.com,guid1,guid2",
            "lastModifiedDateTime": "2023-09-30T05:46:49Z",
            "name": "yoursite",
            "webUrl": "https://yourtenant.sharepoint.com/sites/yoursite",
            "root": {},
            "sensitivityLabel": {},
            "siteCollection": {
                "hostName": "yourtenant.sharepoint.com"
            },
            "title": "your site name"
        }
    ]
}

If you try the same request at the tenant level, you will get all sites your user can access. My response has only one site as the request includes the /sites/yoursite path in the URL.

As you mentioned the Power Automate SharePoint connector, did you know that you can use the Office 365 Groups connector to send HTTP requests to SharePoint (/sites endpoint). It's a standard connector. It's a great workaround to get data from SharePoint with Graph API and not REST API!

1
  • Thanks, it works as expected. But the doc isn't accurate (no $ sign). Or is there any syntax diff between graph.microsoft.com and v2.0 endpoint ?
    – Steve B
    Oct 1, 2023 at 8:58
0

Several possibles answers

  1. jleture's answer, which is quite simple
  2. The graph ID format is <hostname>,<guid of site>,<guid of web>, so it can actually be computed if you have the sharepoint IDs
  3. You can get a "graph" site using the sharepoint ID. For example, to add a content type to a list from the CThub : /_api/v2.0/sites/664097d8-07f2-4b06-9107-604eea39ee55/lists/db411124-720f-48a9-7fbc-73d2704fb352/contentTypes/addCopyFromContentTypeHub, even thought it's under the v2.0 endpoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.