msgraph-sdk-php icon indicating copy to clipboard operation
msgraph-sdk-php copied to clipboard

Trying to list all my onedrive root entries

Open giladsegal10 opened this issue 2 years ago • 2 comments

Hello, I created in php a class that makes an Graph Client (Creates access token and appClient).

I'm trying to create a GET request to list all my onedrive root (files and folders) with this endpoint: GET https://graph.microsoft.com/v1.0/users/{user-id}/drive/root/children

This GET request work in POSTMAN but not in my own php code: $response = $this->appClient->users()->byUserId($this->user_id)->drive()->root()->children()->get($configuration)->wait();

The $configuration is a new DriveRequestBuilderGetRequestConfiguration(). Perhaps I'm using the wrong Import?

Thank You, Gilad Segal

giladsegal10 avatar Dec 24 '23 15:12 giladsegal10

You probably want to use a ChildrenRequestBuilderGetRequestConfiguration object.

GBirch avatar Jan 18 '24 20:01 GBirch

Hello @GBirch is this still an issue:

Given you want items in the root folder, have you considered getting the root folder id, then using the items attribute as below:

$graphClient = new GraphServiceClient($authProvider);

// Fetch drive items using the fluent request builder pattern
try {
    $items = $graphClient->drives()->byDriveId($driveId)->items()->get()->wait();
    foreach ($items as $item) {
        echo "ID: " . $item->getId() . "\n";
        echo "Name: " . $item->getName() . "\n";
        echo "Size: " . $item->getSize() . "\n";
        echo "Folder: " . ($item->getFolder() ? 'Yes' : 'No') . "\n";
        echo "File: " . ($item->getFile() ? 'Yes' : 'No') . "\n";
        echo "\n";
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}


shemogumbe avatar Mar 10 '25 15:03 shemogumbe