Overview
I am familiar in using Microsoft Graph API with File scoping for handling items within root directory if (items specifically folders and files) in Microsoft OneDrive; create/delete/metadata for Folders and upload/delete/metadata for Files.
Using Microsoft Graph API again, I wish to do perform the same actions in handling Folders and Files, create/delete/metadata for folders and upload/delete/metadata for files, in Microsoft SharePoint within the default Drive of root Site as mention prior for OneDrive.
Problem
I having the following issues with Microsoft Graph API in using for handling items within default Drive or root Site:
- Using default Drive ID in handling items within a site's drive.
- Create/Delete/Get-Metadata of a folder item within default Site's Drive.
- Upload/Delete/Get-Metadata of a file item within a parent folder.
The following Microsoft Graph API call returns root site's default drive's metadata**:
curl "https://graph.microsoft.com/v1.0/sites/root/drive" \
--request GET \
--verbose \
--write-out 'HTTPSTATUS:%{http_code}' \
--silent \
--header "authorization: Bearer [** ACCESS_TOKEN **]" \
--header "Content-Type: application/json"
JSON Response example is:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
"createdDateTime": "2012-06-12T17:27:56Z",
"description": "Share a document with the team by adding it to this document library.",
"id": "b!mWxqgLJ9mESqZI4PrP0Gs-F4hgLaCRlCkVuON4nbwzhkKbcyWdM1Tb5WEzNJ0C60",
"lastModifiedDateTime": "2015-03-03T02:39:56Z",
"name": "Shared Documents",
"webUrl": "https://docusign2com.sharepoint.com/Shared%20Documents",
"driveType": "documentLibrary",
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"lastModifiedBy": {
"user": {
"displayName": "System Account"
}
},
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
}
Problem Getting Drive Metadata
Taking the unencoded drive_id for the current default Drive in root Site, [** DRIVE_ID **]
:
"id": "b!mWxqgLJ9mESqZI4PrP0Gs-F4hgLaCRlCkVuON4nbwzhkKbcyWdM1Tb5WEzNJ0C60"
Encode drive_id, [** URL-Encoded DRIVE_ID **]
:
"id": "b%21mWxqgLJ9mESqZI4PrP0Gs-F4hgLaCRlCkVuON4nbwzhkKbcyWdM1Tb5WEzNJ0C60"
Using the encoded drive_id, we can get the metadata for that drive another way:
curl "https://graph.microsoft.com/v1.0/sites/root/drives/[** URL-Encoded DRIVE_ID **]" \
--request GET \
--verbose \
--header "authorization: Bearer [** ACCESS_TOKEN **]" \
--header "Content-Type: application/json"
Response:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
"createdDateTime": "2012-06-12T17:27:56Z",
"description": "Share a document with the team by adding it to this document library.",
"id": "[** DRIVE_ID **]",
"lastModifiedDateTime": "2015-03-03T02:39:56Z",
"name": "Shared Documents",
"webUrl": "https://docusign2com.sharepoint.com/Shared%20Documents",
"driveType": "documentLibrary",
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"lastModifiedBy": {
"user": {
"displayName": "System Account"
}
},
"quota": {
"deleted": 0,
"remaining": 0,
"total": 0,
"used": 0
}
}
Next, I tried listing the items within the root Site's default Drive by appending /items:
curl "https://graph.microsoft.com/v1.0/sites/root/drives/[** URL-Encoded DRIVE_ID **]/items" \
--request GET \
--verbose \
--header "authorization: Bearer [** ACCESS_TOKEN **" \
--header "Content-Type: application/json"
And it fails:
{
"error": {
"code": "invalidRequest",
"message": "The request is malformed or incorrect.",
"innerError": {
"request-id": "0a212014-b386-45d9-9c36-bae2dd6cea8f",
"date": "2020-02-07T06:51:15"
}
}
}
API Path Requested
What is the expected path for getting the list of all items within a default drive's root within root site?
Thank you