phpmicrosoft-graph-sdks

How to get files on root folder drive PHP MS Graph SDK


It can be easy question but the documentation is not clear or has a bug. When you want to get files from known folder, this is the way:

GET /drives/{drive-id}/items/{item-id}/children

<?php
use Microsoft\Graph\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->children()->get()->wait();

you have a DriveId and DriveItemdId, and then you ask files... But if you want the files from root folder of drive, the url is the following:

GET /me/drive/root/children

But, Could you tell me how it is with PHP SDK? Because the documentation show the other, how if you known the folder Id. This is url of documentation: https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=php

Thank you


Solution

  • I'm afraid that in this case you need to call the Graph API twice.

    Once to get yours drive's id and then to get children inside the root of the drive.

    $graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
    
    $drive = $graphServiceClient->me()->drive()->get()->wait();
    
    $result = $graphServiceClient->drives()->byDriveId($drive->getId())->items()->byDriveItemId('root')->children()->get()->wait();
    

    I think that the SDK doesn't generate a client code like

    $result = $graphServiceClient->me()->drive()->items()->byDriveItemId('root')->children()->get()->wait();