Sharepoint Rest V2 API: "General exception while processing"

Z 1 Reputation point
2021-05-31T06:14:08.563+00:00

I am receiving the error (401) Unauthorized: "General exception while processing" while trying to call "https://{tenant-name}.sharepoint.com/_api/v2.0/sites" (with my tenant name substituted in). I found this here: https://learn.microsoft.com/en-us/sharepoint/dev/apis/sharepoint-rest-graph

Request details:
GET https://{tenant-name}.sharepoint.com/_api/v2.0/sites
Authorization: "Bearer {access token}"

I have followed the process for registering an setting up an app in Azure AD: https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app

I believe the root of the issue may be at the stage of acquiring my access token. I have received different errors at this same stage, when acquiring a token with different parameters.

Here are the details of my initial token request (the token is then used in the above request):

POST https://login.microsoftonline.com/{tenant-ID}/oauth2/v2.0/token
Body: client_id=[client_id]&client_secret=[client_secret]&grant_type=client_credentials&scope=[scope]

I have tried the following two scopes in the request body:
api://[app ID]/.default
https://[tenant-name].sharepoint.com/.default

Additionally, if I use the user authorization flow to receive a token, providing scope="offline_access Sites.Read.All"
My application receives the authorization code, which it then exchanges for an access token. When I try to call the same "/sites" request mentioned above (using the access token), I receive the error "(401) Unauthorized: One of the provided arguments is not acceptable."

Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Saurabh Sharma 23,846 Reputation points Microsoft Employee Moderator
    2021-06-01T18:31:33.507+00:00

    Hi @Z ,

    Thanks for using Microsoft Q&A !!
    Have you given SharePoint legacy API permissions to you registered app as you are using SharePoint URL ? Please go to your Azure portal > Azure Active Directory> You registered Application > Click "API Permissions" > "Add a permission" > Choose "SharePoint" > Application permissions > Sites and select the read/write/full control level of permissions from the list. (See screenshot below)
    101496-image.png
    Also, you need to make sure that you have granted "Admin Consent" for the newly added permissions.
    101446-image.png

    Please let me know if this resolves your issue.
    Please refer to the documentation.

    Thanks
    Saurabh


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.