Search code examples
graphsharepoint-online

Unable to get site id of Subsite


i am trying to upload file to a sharepoint subsite document library and struggling in getting the site id / drive id of subsite and document library.

I already follow this article(https://www.sharepointdiary.com/2018/04/sharepoint-online-powershell-to-get-site-collection-web-id.html#:~:text=Here%20is%20how%20to%20find,%3E%2F_api%2Fweb%2Fid) and it is giving me web id but when i am doing the Get call to (https://graph.microsoft.com/v1.0/sites/webid)it is giving below error

{ "error": { "code": "itemNotFound", "message": "Item not found", "innerError": { "date": "2024-05-22T13:43:03", "request-id": "1771c172-052d-4d54-9087-66c891ebb869", "client-request-id": "1771c172-052d-4d54-9087-66c891ebb869" } } }


Solution

  • To get the subsite you have to first get the webid of subsite by following this url "https://.sharepoint.com//_api/web/id" and once you have that you can do a Get call to for subsite details

    https://graph.microsoft.com/v1.0/sites/site-id,webid

    To get the drives list under subsite follow https://graph.microsoft.com/v1.0/sites/site-id,webid/drives