Unable to List Drive Items After Connecting to Microsoft Drive

my-testing-app 0 Reputation points
2024-05-20T07:27:31.8033333+00:00

Hi everyone,

I'm working on a web app and attempting to integrate Microsoft Drive for the first time. I've added the following code in my backend to authenticate:


const MicrosoftStrategy = require('passport-microsoft').Strategy;

passport.use(

    new MicrosoftStrategy(

        {

            authorizationURL: `${process.env.MICROSOFT_URL}/authorize`,

            callbackURL: `${process.env.CALLBACK_URL}/oauth/microsoft/callback`,

            clientID: process.env.MICROSOFT_CLIENT_ID,

            clientSecret: process.env.MICROSOFT_CLIENT_SECRET,

            tokenURL: `${process.env.MICROSOFT_URL}/token`

        },

        (accessToken, refreshToken, profile, cb) => {

            profile.tokens = { microsoft: { accessToken, refreshToken } };

            cb(null, profile);

        }

    )

);

router.get(

    '/auth/microsoft',

    passport.authenticate('microsoft', { scope: ['user.read', 'offline_access', 'Files.Read.All', 'Files.Read', 'Files.ReadWrite.All', 'Sites.Read.All', 'Sites.ReadWrite.All', 'consent'] })

);

The connection is established successfully, and I receive both the accessToken and refreshToken. However, when I try to list the files using the following cURL command:


curl -X GET \

     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \

     -H "Content-Type: application/json" \

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

It returns:


{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)","value":[]}

Despite having several folders and one file in the root directory (as shown in the attached screenshot), no items are listed.

Could anyone help me resolve this issue? Thank you!My-files-OneDrive

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,925 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
906 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hitesh Pachipulusu - MSFT 475 Reputation points Microsoft Vendor
    2024-05-20T09:50:23.8133333+00:00

    Hello @my-testing-app ,

    Thank you for contacting Microsoft Support.

    I have implemented the same Graph API endpoint and able to retrieve the information in response using Graph Explorer.

    Please verify that the account you’re using to execute the Graph API endpoint matches the OneDrive account.

    Please check the screenshots below.

    drives

    drives local

    Hope this helps.

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