How to Fix SharePoint API 401 Errors with Python and MSAL
Question details
Users need to resolve an authentication failure when calling the SharePoint API programmatically using a Python script and MSAL.

- Product
- Microsoft SharePoint / MSAL
- Device & OS
- not provided
- Scenario
- Accessing SharePoint resources programmatically using a Python script authenticated via the Microsoft Authentication Library (MSAL).
- Observed behavior
- The API request fails, returning an HTTP 401 Unauthorized error along with an ID3035 error code.
Ensure you have administrative access to your Microsoft Entra ID (formerly Azure AD) portal to verify application registrations and API permissions.
Verify Azure App Permissions and Token Audience
Ensure your application has the correct API permissions and is requesting an MSAL token for the appropriate SharePoint resource.
A common cause of the ID3035 error is requesting an access token for the Microsoft Graph API but attempting to use it on a SharePoint REST endpoint, or lacking the necessary application permissions.
Log in to the Microsoft Entra ID admin center, navigate to 'App registrations', and select your specific Python application.
Go to 'API permissions' and verify that 'Sites.ReadWrite.All' (or your required scope) is added under the SharePoint API section, not just Microsoft Graph.
Check the status column next to the permissions. Ensure a tenant administrator has clicked 'Grant admin consent' so the status displays a green checkmark.
In your Python MSAL configuration, ensure the scope array uses your specific SharePoint tenant URL (e.g., ['https://yourtenant.sharepoint.com/.default']).

Inspect Request Headers and Payload
Validate the HTTP request parameters, headers, and endpoint URL sent by your Python script.
Consult Microsoft Entra ID Support
If permissions and tokens appear correct, escalate the issue to Azure Active Directory support engineers.
Looking for a Simpler Way to Manage Documents?
While troubleshooting complex Microsoft 365 and SharePoint API errors, you might be looking for a more streamlined, hassle-free way to manage and collaborate on documents. WPS Office offers a lightweight, highly compatible alternative to Microsoft Office, complete with robust built-in cloud storage.
- 1. Download and Install: Download WPS Office from the official website and run the installer.
- 2. Sign In for Cloud Access: Open WPS Office and sign in to activate your free cloud storage workspace.
- 3. Collaborate Instantly: Upload your documents to WPS Cloud to seamlessly share and collaborate with your team.

Frequently Asked Questions
What does error ID3035 mean in SharePoint API?
Error ID3035 typically indicates that the access token provided in your HTTP API request is invalid, expired, or does not have the correct audience or permissions required for the requested SharePoint resource.
How do I check my MSAL token audience in Python?
You can decode the JWT access token generated by MSAL using a Python library like PyJWT or an online tool like jwt.ms. Check the 'aud' (audience) claim to ensure it matches your SharePoint tenant URL rather than Microsoft Graph.
Why am I getting a 401 error even after granting API permissions in Azure?
If you are using the Client Credentials flow, adding the permissions is not enough. You must ensure that a tenant administrator has explicitly clicked the 'Grant admin consent' button in the Azure portal for those permissions to become active.
Does WPS Office provide alternatives for Python automation?
Yes, WPS Office provides secondary development interfaces and macros that enterprise users can leverage to automate document processing workflows, offering an alternative to complex Microsoft Office and SharePoint API integrations.




