"ObjectHandle is invalid" for one of user's personal drives

Dan Gravell 0 Reputation points
2024-05-01T09:18:17.31+00:00

I have written an integration with OneDrive that traverses the user's drives and folders.

I was recently contacted with a bug for a user that had multiple personal drives. Here's what was returned for /me/drives:

GET /me/drives
[0] => Microsoft\Graph\Model\Drive Object
    (
        [createdDateTime] => 2024-04-16T17:51:30Z
        [description] => ****
        [id] => b!ZgXcUExgQkiYkeYENuOZof3MA4U_rxRJsnlh9pDBY80Lv2orpc9-PLQ5Lo7FaHMN
        [lastModifiedDateTime] => 2024-04-16T17:51:30Z
        [name] => OneDrive
        [webUrl] => https://my.microsoftpersonalcontent.com/personal/540541d728bc6c6b/AEEE112EFFF94E2C89C603821FF83501
        [driveType] => personal
        [createdBy] => Array
            (
                [user] => Array
                    (
                        [displayName] => SharePoint App
                    )
            )
        [owner] => Array
            (
                [user] => Array
                    (
                        [email] => ****
                        [displayName] => ****
                    )
            )
        [quota] => Array
            (
                [deleted] => 0
                [remaining] => 943174818201
                [state] => normal
                [total] => 1104880336896
                [used] => 161705518695
                [storagePlanInformation] => Array
                    (
                        [upgradeAvailable] => 
                    )
            )
    )
[1] => Microsoft\Graph\Model\Drive Object
    (
        [createdDateTime] => 2024-04-16T17:51:28Z
        [description] => 
        [id] => 540541d728bc6c6b
        [lastModifiedDateTime] => 2024-04-26T20:24:25Z
        [name] => OneDrive
        [webUrl] => https://my.microsoftpersonalcontent.com/personal/540541d728bc6c6b/Documents
        [driveType] => personal
        [createdBy] => Array
            (
                [user] => Array
                    (
                        [displayName] => SharePoint App
                    )
            )
        [lastModifiedBy] => Array
            (
                [user] => Array
                    (
                        [displayName] => System Account
                    )
            )
        [owner] => Array
            (
                [user] => Array
                    (
                        [email] => ****
                        [displayName] => ****
                    )
            )
        [quota] => Array
            (
                [deleted] => 0
                [remaining] => 943174818201
                [state] => normal
                [total] => 1104880336896
                [used] => 161705518695
                [storagePlanInformation] => Array
                    (
                        [upgradeAvailable] => 
                    )
            )
    )

(Sorry for the redactions and formatting)

I then try to get a listing of the root for each drive.

However, only the second drive above works:

GET /me/drives/540541d728bc6c6b/items/root/children

If I try the first drive:

GET /me/drives/b!ZgXcUExgQkiYkeYENuOZof3MA4U_rxRJsnlh9pDBY80Lv2orpc9-PLQ5Lo7FaHMN/items/root/children

I get:

`GET https://graph.microsoft.com/v1.0/me/drives/b!ZgXcUExgQkiYkeYENuOZof3MA4U_rxRJsnlh9pDBY80Lv2orpc9-PLQ5Lo7FaHMN/root/children?$top=999` resulted in a `400 Bad Request` response:
{"error":{"code":"invalidRequest","message":"ObjectHandle is Invalid","innerError":{"date":"2024-05-01T08:48:55","request-id":"93c593cd-6126-453e-84ba-e4d202cee548","client-request-id":"93c593cd-6126-453e-84ba-e4d202cee548"}}}

Obviously the drive IDs have a different format. I also noticed that even though the drive IDs are different, the webUrl uses the same (working) drive ID.

Is there something different about the first drive that means I shouldn't be trying to read its root listing?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,813 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CharanyaB-MSFT 1,421 Reputation points Microsoft Vendor
    2024-05-21T15:30:09.4733333+00:00

    Hello @Dan Gravell,

    Thank you for reaching Microsoft.

    A 400 Bad Request error occurs when the request is malformed or incorrect. It's advisable to check whether you are using the correct drive ID in your Graph API request.

    Additionally, since the API "GET https://graph.microsoft.com/v1.0/me/drives/{drive-id}/root/children?$top=999" is functioning correctly, please ensure that the drive ID used in your Graph API requests is correct and that the drive is located within your tenant and active.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments