Search code examples
sharepointmicrosoft-graph-apionenoteonenote-api

Get sharepoint siteurl using weburl with MS Graph


I have onenote notebooks hosted at sharedpoint. I have a weburl to access that notebook. How I can retrieve siteId and siteCollectionId using webUrl with MS Graph API.

Sample webUrl is -

https://companyall-my.sharepoint.com/personal/ash_desh_company_com/Documents/Notebooks/Notebook1


Solution

  • If you encode the webUrl using this process and then make a request to the following you should be able to access the ids:

    https://graph.microsoft.com/v1.0/shares/{encodedurl}/site?select=sharepointIds

    As an example, for the example URL you provided it would look like:

    https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly9jb21wYW55YWxsLW15LnNoYXJlcG9pbnQuY29tL3BlcnNvbmFsL2FzaF9kZXNoX2NvbXBhbnlfY29tL0RvY3VtZW50cy9Ob3RlYm9va3MvTm90ZWJvb2sx/site?select=sharepointIds

    Note that the ids are returned using the older nomenclature, so siteId = siteCollectionId and webId = siteId