Hello @Yemi Shin
The error message access denied
of code 403 you are getting because, your access token doesn't contain sufficient API permission to list the sharepointId
of your drive.
I got the same error message:
To resolve this error, you need to add at least delegated type Files.Read.All
permission or higher privileged permission like Sites.Read.All
to your registered application and generate the access token. For more details Refer this MsDoc.
For delegated type permission, you can use authorization_code flow which requires user-interaction. To get code
, I ran below authorization request in browser:
https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize?
client_id=<application-id of your registered application>
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=https://graph.microsoft.com/Files.Read.All
&state=12345
After successfully creating authorization_code
, Generated access token using below parameters:
POST https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
client_id: <application-id>
client_secret: <client-secret>
scope: https://graph.microsoft.com/Files.Read.All
grant_type: authorization_code
code: <authorization_code generated from browser>
redirect_uri: <REDIRECT_URI>
Response:
Ensure your generated access token should contains scp: Files.Read.All
, when you decode your token on https://jwt.ms
Now, for listing the sharePointIds
of your drive:
GET https://graph.microsoft.com/v1.0/drives/<drive-id>?&$select=sharePointIds
Response:
If you are using Microsoft Graph Explorer, need to add permission of Files.Read.All
in Modify permission tab by adding consent:
Use same query:
GET https://graph.microsoft.com/v1.0/drives/<drive-id>?&$select=sharePointIds
Reference:
I hope this helps you!
If this answer was helpful to you, please click "Accept Answer" and mark Yes to help other community members.
If you have more questions or are still experiencing issues, feel free to ask in the "comments" section and I’ll be happy to assist you.