Haris Osmanagić
Haris Osmanagić

Reputation: 1285

All root drive items in one SharePoint have same IDs?

This question is about root drive items in SharePoint drives, i.e. document libraries (because doc. libraries are backed by drives).

Namely, in a SharePoint site, I have multiple document libraries: the default one (called 'Documents') and a few more (let's call them DL1 and DL2).

To get the root drive item, in the drive backing DL1, I use this:

GET https://graph.microsoft.com/v1.0/drives/dl1-drive-id/root

I use a similar query to get the root drive item in the drive backing DL2.

However, all of those root drive items have the same ID. The drives, of course, have different IDs.

I tested this on two tenants and it's the same behavior. Is this expected?

Upvotes: 0

Views: 952

Answers (2)

Dragan Panjkov
Dragan Panjkov

Reputation: 4332

The element IDs are not guaranteed to be unique outside of their parent scope (for this case, parent scope is root folder of the document library).

However, the fact that root elements in different document libraries have same IDs is the side effect of the SharePoint provisioning process. As Jeremy Kelley (one of PMs that works on Microsoft Graph APIs for SharePoint) wrote in an answer to my question on Twitter: "Most provisioning of things in SharePoint is optimized partially through the use of static templates to stamp things out rapidly. Which means each thing created using that template has the same ID."

Upvotes: 1

Dragan Panjkov
Dragan Panjkov

Reputation: 4332

Can you elaborate: How do you retrieve Drive IDs?

You should first retrieve correct Drive ID based on the SharePoint site by performing

GET /sites/{siteId}/drive

or for the Microsoft 365 Group

GET /groups/{groupId}/drive

and then you can refer it by correct ID. You can test these queries in Graph Explorer https://aka.ms/ge

The official documentation for different use cases for retrieving drives is here: https://learn.microsoft.com/en-us/graph/api/drive-get?view=graph-rest-1.0&tabs=http

Upvotes: 0

Related Questions