Microsoft Graph / OneDrive : The resource could not be found

Microsoft Graph gives you access to a large range of features and data (Outlook, Delve, Azure AD…) using its REST API.

Among these features, you are able to retrieve content from the “OneDrive for Business” service associated to your Office 365 account.

To do this, you just have to call the following URL that will return all the items stored in the root folder of your personal document library.

GET https://graph.microsoft.com/v1.0/me/drive/root/children

By calling that URL, the server will return a JSON response such as the following (the response shown here was truncated for brevity) :

{
  value = ({
    @odata.id = "users/31950312-e7dd-44de-bfaa-4d8274e4d6a0/drive/root/children/01ZWNXWXJYRUGTTJRMQZB2L2YE4NQK4CIF",
    createdBy = { ... },
    createdDateTime = "...",
    eTag = "...",
    folder = { ... },
    id = "01ZWNXWXJYRUGTTJRMQZB2L2YE4NQK4CIF",
    lastModifiedBy = { ... },
    lastModifiedDateTime = "...",
    name = "...",
    parentReference = { ... },
    size = 0,
    webUrl = "..."
  },
  {
    @odata.id = "users/31950312-e7dd-44de-bfaa-4d8274e4d6a0/drive/root/children/01ZWNXWXJ3G5EOS6XJRRCJ54PQZQAJIM3H",
    createdBy = { ... },
    createdDateTime = "...",
    eTag = "...",
    folder = { ... },
    id = "01ZWNXWXJ3G5EOS6XJRRCJ54PQZQAJIM3H",
    lastModifiedBy = { ... },
    lastModifiedDateTime = "...",
    name = "...",
    parentReference = { ... },
    size = 0,
    webUrl = "..."
  })
}

This sample has 2 folders with their respective properties. One of the important parts in the response is the parameter named “@odata.id” which is the URL associated to the object, and used by the API to uniquely identify an item.

In the case of a folder, it could have children (folders and files). If you want to retrieve these children, you have to concatenate “/children” to the unique identifier of the item.

With the first folder of the previous JSON response, it should look like this :

GET https://graph.microsoft.com/v1.0/users/.../drive/root/children/01ZWNXWXJYRUGTTJRMQZB2L2YE4NQK4CIF/children

But if you call that URL, you get the following error message :

The resource could not be found.

This message means that Microsoft Graph is unable to process your request. It’s weird because the URL was generated by the server and returned in the JSON response.

So how can you get to access the children of this item ?

Now that we have retrieved the ID for the item (see the ID value in the JSON response), we are able to build our own URL to retrieve its children.

In Microsoft Graph / OneDrive API, each item is accessible through an URL such as “…/v1.0/users/{user_id}/drive/items/{item_id}”. So if we build our URL by respecting that schema, it works without errors.

In our previous example, the URL to call will be :

GET https://graph.microsoft.com/v1.0/users/.../drive/items/01ZWNXWXJYRUGTTJRMQZB2L2YE4NQK4CIF/children

If you want to play with Microsoft Graph APIs with data stored on your tenant, you can use this site created and hosted by Microsoft : https://graphexplorer2.azurewebsites.net

Advertisements

2 thoughts on “Microsoft Graph / OneDrive : The resource could not be found

  1. Pingback: Episode 076 on Word add-ins with Juan Balmori Labra and Martin Seifert—Office 365 Developer Podcast | Alt-Tech

  2. Dhruti

    hello i do not get id like this “01ZWNXWXJ3G5EOS6XJRRCJ54PQZQAJIM3H” but i get the id like “7FA7C48C26BC284B!111”. please tell me how do i get this? when i want to access that file from graph api it is fire error “RecourceNotFound”. please help me.

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s