Hi Alexandra Hooser,
Thanks for reaching out to Microsoft!
Yes, you're correct. The "Access denied" error occurs because your application currently has only the "Sites.Selected" permission. Using a token with this permission alone results in the error. To properly assign the "Sites.Selected" permission, please follow these steps:
Step 1: Register two applications in your tenant:
App1: Assign the "Sites.FullControl" application permission.
App2: Assign the "Sites.Selected" application permission.
Step 2: Use Postman with the Microsoft Graph API to assign restricted site permissions to App2. Generate a token using App1 and send the following request:
POST https://graph.microsoft.com/v1.0/sites/{siteId}/permissions
Content-Type: application/json
{
"roles": ["read"],
"grantedToIdentities": [{
"application": {
"id": "App ID of App2",
"displayName": "Display name of App2"
}
}]
}
Step 3: To verify the permissions have been successfully assigned, generate a token using App2 and use the following API:
GET https://graph.microsoft.com/v1.0/sites/{siteId}
For additional details, please refer to the documentation: Develop applications that use Sites.Selected permissions for SPO sites
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.