Search code examples
microsoft-graph-apionedrive

OneDrive API (rest) . Folders and Files on Drives


I try to make integration with OneDrive, using the API https://dev.onedrive.com/getting-started.htm

I make auth work and i can get list of drives in the account . When i execute the API call /me/drives i am getting the list of drives fine.

But i can not find how to get list of folders on a drive, subfolders of a folder etc.

From the docs i can see there are some API for this, but it doesn't work for me. https://dev.onedrive.com/items/list.htm

I have to execute on of.

GET /drive/items/{item-id}/children
GET /drive/root:/{item-path}:/children

But it doesn't work. I have a Drive ID from a list of drives. When i execute GET /drive/items/DRIVEID/children i have error "Access denied. You do not have permission to perform this action or access this resource."

How to do this operation? should i use a drive ID or name? maybe the url is wrong, what must be the correct url if i have a drive name, ID ?


Solution

  • I have found how to do this. To understand i had to install some other tool where OneDrive API is used and debugged traffic with a https sniffer.

    So, if endpoint is https://graph.microsoft.com/v1.0/me/ then paths are

    /drives/DRIVEID/root/children
    

    for root of drive

    /drives/DRIVEID/root:myfolder/subfolder:/children
    

    for a folder myfolder/subfolder

    Final url is like

    https://graph.microsoft.com/v1.0/me/drives/DRIVEID/root:myfolder/subfolder:/children