Unable to Run SharePoint API Call Using Service Principal in Power Automate

Harsha Jha 61 Reputation points
2025-06-09T17:30:05.32+00:00

I am currently unable to execute a SharePoint API call using a Service Principal within Power Automate.
The same script works successfully when using SharePoint’s built-in HTTP connector, which relies on user credentials.
Below is a summary of the request and the error encountered:

Request Details:

{
    "uri": "https://abc.sharepoint.com/teams/Test/_api/web/lists/GetByTitle('Documents')/fields",
    "method": "POST",
    "headers": {
        "Accept": "application/json;odata=verbose",
        "Content-Type": "application/json;odata=verbose"
    },
    "authentication": {
        "authority": "https://login.microsoftonline.com/*sanitized*",
        "tenant": "*sanitized*",
        "audience": "https://abc.sharepoint.com",
        "clientId": "*sanitized*",        
		"secret": "*sanitized*",
        "type": "ActiveDirectoryOAuth"
    },
    "body": {
        "__metadata": {
            "type": "SP.FieldChoice"
        },
        "FieldTypeKind": 6,
        "Title": "Reference",
        "Choices": {
            "results": [
                "None",
                "Keep"
            ]
        },
        "Required": true,
        "DefaultValue": "None",
        "Hidden": false
    }
}

Error Received:

BadGateway Http request failed as there is an error getting AD OAuth token: 'Failed to extract error details from response content '''.

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Camila Th 1,840 Reputation points Microsoft External Staff Moderator
    2025-06-10T04:13:52.35+00:00

    Hi @Harsha Jha

    Good day! Welcome to Q&A forum.

    Here are some articles about Setup a Service Principal in Power Automate for your reference:

    Setup a Service Principal in Power Automate » Benedikt's Power Platform Blog

    A Visual Guide To Power Platform Service Principal Setup

    Since your issue is more related to Power Automate flow, in order to better solve your problem, it's suggested that you could post your case in Power Automate forum Microsoft Power Platform Community Forum Thread for more professional advice.

    Thanks for your understanding and cooperation! Hope you have a nice day!

    Hope these information helps.

    Please do let us know if you have any further queries.


    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.

    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.