none
Office 365 Files REST API - Get direct children in the root of the default document library RRS feed

  • Question

  • I'm trying to work with Office 365 Files REST API which works just fine except one thing that I'm struggling with.

    What I need for my application is to make an explorer like browse capability for OneDrive for business Document Library.

    My problem is that I don't know how to get the direct children in the root of the Document library

    The API request GET ../_api/files will retrieve all files and folders in the default document library, including files and folders from sub-directories.

    What I need is basically the functionality of the API request GET ../_api/files(<folder_path>)/Children that works also for the root folder of the Document library. The problem is that I couldn't find a way set <folder_path> as the root folder. 

    I found out that the API call ../_api/web/getfolderbyserverrelativeurl(<folder_server_relative_path>)/Folders and _api/web/getfolderbyserverrelativeurl(<folder_server_relative_path>)/Files works as expected resulting the only the direct children of the root folder if the folder_server_relative_path is the path of the document library. The problem with this API call is that it's requires server relative path of the (default) document library (which i don't have) and the result has a different schema compared to the ../_api/files REST API call.

    Can somebody help me with this problem?


    David


    • Edited by David Weisz Sunday, October 12, 2014 2:42 PM
    Sunday, October 12, 2014 2:42 PM

Answers

  • What you need to request is <your endpoint uri>/files/root/children. This will give you the items in the root of the OneDrive for business.

    Tom Wisnowski

    • Marked as answer by David Weisz Sunday, March 15, 2015 6:52 AM
    Saturday, March 14, 2015 5:27 PM

All replies

  • Hi,

    According to your post, my understanding is that you want to get direct children in the root of the default document library using REST API.

    To get all folders and files from default document library, you can use

     http://site url/_api/web/lists/GetByTitle (‘libraryname’)/items

    To get a single folder or file in the root of the default document library, you can use:

    http://site url/_api/web/lists/GetByTitle(‘libraryname ')/items(item id)

    For more information, you can refer to:

    Working with lists and list items with REST

    Thanks,

    Linda Li                

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Linda Li
    TechNet Community Support

    Monday, October 13, 2014 2:44 AM
  • First thanks for the fast answer. Let me explain my use case in more details.

    I'm trying to work with the new summer release of the Office 365 API tool for Visual Studio 2013 (update 3)

    I found no reasonable way to retrieve the direct children of the root folder from my One Drive for business Document Library using the newly added SharePointClient library.

    The API call of `SharePointClient.Files` will retrieve all the files and folders from the whole document library including sub-folders. So in order to get only the direct children I have to page through all the documents and folders and analyze their URL, which is not acceptable for my application scenario. For a sub-folder I can get the direct children like this: `SharePointClient.Files["<folder_id>"].ToFolder().Children` This is what I need but it can't be applied to the root folder.

    So what I did I've checked what REST API calls this library makes and I've tried to find out if there is a way to achieve my goal at least using direct REST API call. It seems like the functionality is missing from the REST API itself. 

    The http://site url/_api/web/lists/GetByTitle(‘libraryname’)/items API call also retrieves all the items hierarchy from the library (including items from sub-folders) and the result XML "schema" (fields and the meaning of the ID) differs from the one used by the calls by SharePointClient library. (for example the "Id" is a number when the /items is called but when /_api/files is called the "Id" is the relative path to the document library)

    Basically what I need can be achieved with the call to http://site url/_api/web/lists/GetByTitle(‘libraryname’)/rootfolder/files and http://site url/_api/web/lists/GetByTitle(‘libraryname’)/rootfolder/folders but again the schema of the result differs from the one used in SharePointClient library. This means that in order to get  the direct children of the root I will need to re-implement a good part of the SharePointClient library. It seams like there is 2 kind of REST API is implemented. ( missing  "Id" and "url" fields, etc)

    Also there is no convenient way to get the Name or the GUID of the default document library which the SharePointClient.Files (https://site_url/_api/file) automatically uses. The DiscoveryContext.DiscoverCapability for "MyFiles" doesn't gives any hint either.


    David



    • Edited by David Weisz Monday, October 13, 2014 5:00 PM
    Monday, October 13, 2014 1:19 PM
  • What you need to request is <your endpoint uri>/files/root/children. This will give you the items in the root of the OneDrive for business.

    Tom Wisnowski

    • Marked as answer by David Weisz Sunday, March 15, 2015 6:52 AM
    Saturday, March 14, 2015 5:27 PM
  • What you need to request is <your endpoint uri>/files/root/children. This will give you the items in the root of the OneDrive for business.

    Tom Wisnowski

    Hi,

    Thank you for the answer.

    This problem was fixed in a newer API that was released after my initial post. This thread should have been marked as resolved by me.

    David.


    David

    Sunday, March 15, 2015 6:52 AM