I need to be able to find a driveItem from the Microsoft Graph API, given only a document URL in this sort of format:
https://tenant.sharepoint.com/sites/somesite/somefolder/somedocument.doc
I know it is possible to do the opposite, e.g. get a document URL from a driveItem, but how do I get the driveItem when I only have a document URL?
2
Answers
For sample, I created folder in SharePoint site and uploaded document in the folder:
To fetch a drive Item ID given only a document URL via Microsoft Graph API, check the below:
To verify the same, I passed the Drive ID and Drive Item ID to check if it fetches the document:
If you don’t have Site ID, you can pass the name of the site to fetch the site ID:
You can use Search API, filter
driveItem
entity type, and specify the document URL in thequeryString
The response will contain
resource
property with innerid
which isdriveItemId
you need. TheparentReference
property contains additional details likedriveId
Another way is to get file by relative path, but it requires the knowledge of
siteId
anddriveId
related to the certain document library.