Unable to fetch page content through Legacy SharePoint REST API

Anant Hiremath 20 Reputation points
2024-11-27T07:22:00.2466667+00:00

Hi,

I am trying to fetch the page content of SharePoint Site Pages using the SharePoint Legacy REST API. While I am able to successfully retrieve page content from Communication Sites that is default SharePoint page, I encounter a "403: Forbidden - Unauthorized operation" error when attempting to retrieve content for Site Pages I have created manually.

Scenario:

  1. Get page content for Communication Sites: [SUCCESS]
    1. Data Fetching for: https://contoso.sharepoint.com/SitePages/Forms/ByAuthor.aspx
    2. API endpoint used: https://contoso.sharepoint.com/_api/web/lists/getbytitle('Site Pages')/items
    3. Screenshot 2024-11-27 113848
  2. Get page content for other sites: [FORBIDDEN]
    1. Data Fetching for: https://contoso.sharepoint.com/sites/TestStandardTemp/SitePages/Forms/ByAuthor.aspx
    2. API Endpoint used: https://contoso.sharepoint.com/sites/TestStandardTemp/_api/web/lists/getbytitle('Site Pages')/items
    3. Screenshot 2024-11-27 114629
    4. Screenshot 2024-11-27 114718

What could be causing the "Forbidden" error when querying the Site Pages from the TestStandardTemp site?

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,095 questions
{count} votes

Accepted answer
  1. Yanli Jiang - MSFT 27,486 Reputation points Microsoft Vendor
    2024-11-28T10:17:09.3666667+00:00

    Hi @Anant Hiremath ,

    Welcome to Q&A forum!

    Sorry for the late update. I tested it and didn't encounter the problem you mentioned. According to the error message, it seems to be a permission problem. But this is a common error. There are many reasons for this error, and the specific cause cannot be determined at present. I did a lot of searching and didn't find an effective solution. We recommend that you use jwt to parse the access token to check the permissions. Or, please explain the verification method you use so that I can reproduce it.

    Non-official, just for reference.

    In addition, you can use the Graph API to get Site Pages:

    GET /sites/{site-id}/pages/microsoft.graph.sitePage
    

    This is my test:

    112801

    Good day!


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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Anant Hiremath 20 Reputation points
    2024-11-29T11:52:42.88+00:00

    Hi @Yanli Jiang - MSFT, Thanks for the quick response.

    Actually, I found out that it's an authentication token issue. The token I used was generated from this API https://accounts.accesscontrol.windows.net/:tenantId/tokens/OAuth/2, but the API to get site data from the legacy SharePoint REST API, which was created by the user, requires a delegated token in order to retrieve the data.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.