Access token for Sharepoint API is not valid - AudienceUriValidationFailedException

Kristina Razmoska 0 Reputation points
2024-01-10T10:35:53.9666667+00:00

Hi, I am trying to make few Rest API calls using Postman for SharePoint online, but I am receiving this error: {"error_description":"Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."}

curl --request POST \ --url 'https://login.microsoftonline.com/[Tenant-ID]/oauth2/v2.0/token' \

--header 'Content-Type: application/x-www-form-urlencoded' \

--data-urlencode 'client_id=[Client-ID]' \

--data-urlencode 'scope=[Resource]/.default' \

--data-urlencode 'client_secret=[Client-Secret]' \

--data-urlencode 'grant_type=client_credentials'

For "scope" I have tried different values such as:

2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default

{tenant ID}/.default

I am receiving access token from this request, but when I am trying later to use that token it is throwing error.

I can not use graph API's because with graph API's and token I am not able to create SharePoint site.

Thank you in advanced. get_token

Screenshot_1

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,501 Reputation points Microsoft External Staff
    2024-01-11T02:09:17.6566667+00:00

    Hi @Kristina Razmoska, You could post request to https://accounts.accesscontrol.windows.net/"Tenant ID"/tokens/OAuth/2 and the request body should be like following | | |grant_type|client_credentials|client_credentials| |client_id|ClientID**@TenantID|Refer below for the value| |client_secret|ClientSecret|Refer below for the value| |resource|resource/SiteDomain@**TenantID|Refer below for the value|

    POST operation status 401 unauthorized: Postman tool SharePoint online REST API

    POST content type, client_id, client_secret_Postman tool SharePoint online REST API

    Here is the article for the detail steps https://global-sharepoint.com/sharepoint-online/in-4-steps-access-sharepoint-online-data-using-postman-tool/

    ---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.

    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.