Need SiteId for Sharepoint site with no /sites/ in WebUrl

Joseph Tinglof 20 Reputation points
2024-02-07T00:22:36.49+00:00

I have a Sharepoint List that I need to send data to using Graph. But I can't figure out the SiteId of the site that the list is on. I've noticed that the url of this site is not in the standard format. It is missing the "/sites/". So, the web url of the list is [companyname].sharepoint.com/[sitename]/Lists/[listname]. When I use the search for sites Graph request using its name it does not appear. In my Sharepoint there is also an unused site with the exact same name that does include /sites/ in its WebUrl. I created an identical list on this other site. So that url is [companyname].sharepoint.com/sites/[sitename]/Lists/[listname]. I am able to find the SiteId of this other site by using a graph search request. With the SiteId I am able to send data to the duplicate list using my program, so I know my program is working. What could be causing the first site to appear this way? How to do I find it's SiteId?

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,476 Reputation points Microsoft External Staff
    2024-02-08T01:30:35.4+00:00

    Hi @Joseph Tinglof, I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum. By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread: [Need SiteId for Sharepoint site with no /sites/ in WebUrl] Issue Symptom: Unable to get Sharepoint site id with no /sites/ in WebUrl. Solution: Following request get the SiteId

    GET https://graph.microsoft.com/v1.0/sites/{companyName}.sharepoint.com:/{siteName}?$select=id 
    

    ---You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,476 Reputation points Microsoft External Staff
    2024-02-07T06:16:48.0833333+00:00

    Hi @Joseph Tinglof, You could use search query to get the site id. Please refer to following api and document

    GET /sites?search={query}
    

    https://learn.microsoft.com/en-us/graph/api/site-search?view=graph-rest-1.0&tabs=http#http-request

    ---If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Joseph Tinglof 20 Reputation points
    2024-02-07T19:22:37.5066667+00:00

    I figured it out. I used this request to get the SiteId from the WebUrl:

    GET https://graph.microsoft.com/v1.0/sites/{companyName}.sharepoint.com:/{siteName}?$select=id
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.