Reputation: 131
I am trying to list all files in another user's OneDrive.
I am calling GET /users/{user-id}/drive/items/{item-id}/children
but my problem is that I do not know how to get the {item-id}
.
I tried using https://graph.microsoft.com/v1.0/users/{userid}/drives
but it is not showing any item ids.
Subsequently, once I get the id, I will use the copy command POST /users/{userId}/drive/items/{itemId}/copy
to copy items.
Upvotes: 1
Views: 2550
Reputation: 33094
If you do not know the ID or Path for the DriveItem
, you'll need to start at the root of the Drive
and walk the folder structure until your find the file(s) you're looking for.
Your first call would be to /users/{id|userPrincipalName}/drive/root/children?$select=id,name,folder,file
. This will list the children's id
, name
, and either the folder
or file
data (depending on the item type) from the root
folder:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('id')/drive/root/children(id,name,folder,file)",
"value": [
{
"@odata.etag": "\"{etag},1\"",
"id": "folderId",
"name": "My Folder",
"folder": {
"childCount": 10
}
},
{
"@odata.etag": "\"{etag},1\"",
"id": "fileId",
"name": "filename.ext",
"file": {
"mimeType": "type",
"hashes": {
"quickXorHash": "hash"
}
}
}
]
}
You then execute the same call against each of the folders to get their children, repeating the pattern until your find the file you're looking for:
/users/{id|userPrincipalName}/drive/items/{folderId}/children?$select=id,name,folder,file`
Alternatively, you could simply search for the file using /users/{id|userPrincipalName}/drive/root/search(q='{search-text}')
.
Upvotes: 1
Reputation: 11
You probably need to query root to get childIDs for files/folders
GET https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children
Upvotes: 0