Used this agent to

Edward 66 Reputation points
2026-08-04T14:24:58.4866667+00:00

https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread#using-this-principal-with-pnp-powershell

https://pypi.org/project/office365-rest-python-client/#Working-with-SharePoint-API

I followed this two guide to set up an App in Entra and use the python library to make the call. However, when I use the call, it's giving me a 401 error.

How do i troubleshoot this? I do see that 'FullControl' is allowed in the app (Entra) and we used the certificate but i can't seem to fix the 401 error. I noticed few others having the same problem but no solution.

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

2 answers

Sort by: Most helpful
  1. Jayden-P 605 Reputation points Independent Advisor
    2026-08-04T18:30:13.5566667+00:00

    Thanks for the additional information.

    One thing that stands out from the screenshot is that the SharePoint permissions shown are Delegated permissions (AllSites.Read and AllSites.FullControl). Since you're using with_client_certificate(...), you're using the app-only / client credential flow, which requires Application permissions rather than Delegated permissions. Microsoft's App-Only guidance also describes using SharePoint application permissions for certificate-based authentication.

    User's image

    In your Entra app registration, it should look something like this:

    User's image

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Jayden-P 605 Reputation points Independent Advisor
    2026-08-04T14:52:48.63+00:00

    Hi @Edward

    Are you accessing SharePoint REST via ClientContext or are you using the library's Microsoft Graph capabilities?Screenshot 2026-08-04 at 21.52.02

    The document you provided supports both SharePoint and Graph APIs, and a 401 can occur if the app permissions and token audience do not match the endpoint being called. For example, a token issued for Microsoft Graph will not be accepted by SharePoint REST endpoints, and vice versa

    If you are trying to call SharePoint REST API, you can check the following things:

    1. Verify the access token is being issued correctly

    If you're using the certificate-based client credential flow, ensure the token is requested for SharePoint and not Microsoft Graph: scopes = ["https://<tenant>.sharepoint.com/.default"]

    After obtaining the token, decode it using https://jwt.ms and verify

    "aud": "https://<tenant>.sharepoint.com".

    "roles": "Sites.FullControl.All"

    1. Confirm admin consent was granted in Entra ID, navigate to App Registration > API Permissions > Make sure the API permission status is "Granted for <tenant>"
    2. Verify you're using SharePoint permissions, double-check whether the permission was added under SharePoint or Microsoft Graph. It should be SharePoint.

    I look forward for your response.

    Was this answer helpful?


Your answer

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