Getting id for subsites in Sharepoint using Microsoft graph api

User3 40 Reputation points
2024-06-28T11:21:52.99+00:00

I am using Microsoft Graph API to list files in Sharepoint sites.

I am trying to list the files in a subsite but I am not able to get the id of the subsite.

When I run https://graph.microsoft.com/v1.0/sites/{parent_site_id}/sites in Graph Explorer, I can see all the subsites listed but the id is the same as that of the parent site's id for all of them.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,200 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,108 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rohit Mishra 1 Reputation point
    2024-06-29T21:02:22.41+00:00

    Please recheck the response, it must be having id in the following format:

    "id": "<hostname>,<site id>,<web id>"

    Here web id is subsite id.

    0 comments No comments

  2. Ling Zhou_MSFT 14,845 Reputation points Microsoft Vendor
    2024-07-01T02:24:29.9066667+00:00

    Hi @User3,

    Your URL is fine, maybe your Parent Site ID is wrong. Please navigate to this address to check if your Parent Site ID is correct:

    https://<tenant>.sharepoint.com/sites/<site-url>/_api/site/id
    

    User's image

    Then try to get the IDs of all subsites under the site again. The same number of data will be returned in the value as the number of subsites.User's image

    The id of the subsite is the last one:

    User's image


    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.

    0 comments No comments