Skip to content

get access denied from specific sites using sharepoint REST APIs #8858

@mistysya

Description

@mistysya

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

SharePoint REST API

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • browser version
  • SPFx version
  • Node.js version
  • etc

Issue description

Hi, I used below SharePoint REST API to get the site's information.
https://graph.microsoft.com/v1.0/sites/{site-id}
https://graph.microsoft.com/v1.0/sites/{site-id}/drives

However, when I used some site-ids, I received the following response:

{
    "error": {
        "code": "accessDenied",
        "message": "Access denied",
        "innerError": {
            "date": "2023-03-30T01:20:24",
            "request-id": "a56c6c25-1b86-47d7-84aa-6acb458becfb",
            "client-request-id": "a56c6c25-1b86-47d7-84aa-6acb458becfb"
        }
    }
}

When I tried the same REST API with other site-ids in the same tenant and token, I received the expected response:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
    "createdDateTime": "2023-03-30T04:08:20.17Z",
    "description": "",
    "id": "XXXX",
    "lastModifiedDateTime": "2023-03-30T04:19:07Z",
    "name": "XXXX",
    "webUrl": "XXXX",
    "displayName": "XXXX",
    "root": {},
    "siteCollection": {
        "hostname": "XXXX"
    }
}

I also checked my JWT token at jwt.ms and confirmed that I have the Sites.FullControl.All permission, and I can receive the expected response with the same token.

{
  "aud": "https://graph.microsoft.com",
  "iss": "https://sts.windows.net/dcb0e1d1-6cde-4420-a658-ede52a8bead1/",
  "iat": 1680155149,
  "nbf": 1680155149,
  "exp": 1680159049,
  ......
  "roles": [
    "TeamSettings.ReadWrite.All",
    "Mail.ReadWrite",
    "User.ReadWrite.All",
    "TeamsTab.Create",
    "Channel.ReadBasic.All",
    "Directory.ReadWrite.All",
    "TeamsTab.ReadWrite.All",
    "Contacts.ReadWrite",
    "Team.Create",
    "Group.ReadWrite.All",
    "Files.ReadWrite.All",
    "TeamMember.ReadWrite.All",
    "Team.ReadBasic.All",
    "ChannelMessage.Read.All",
    "Calendars.ReadWrite",
    "Chat.ReadWrite.All",
    "ChannelMember.ReadWrite.All",
    "ChannelSettings.ReadWrite.All",
    "Channel.Create",
    "Sites.FullControl.All"
  ],
  "sub": "30035663-67f3-468e-a0a8-1cdcc40f30c6",
  "tenant_region_scope": "AS",
  ......
}

I would like to know why I only received this response from specific sites. What does the error message mean? Are there any settings that could cause this issue?

Thank you for your reply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:csom/rest/apiCategory: SharePoint Client Side Object Model SDK / REST APItype:archive-old-issueIssues which are closed as tool old for active work

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions