How to call a REST API end point in ADF using service principal authentication?

Anoop Jose 1 Reputation point Microsoft Employee
2024-03-20T04:27:23.51+00:00

I have an ADF workspace in MSFT tenant and I need to invoke a REST API hosted in AME tenant. REST API needs AME based token to accept any request.

I have an AME Serice principal which used in the linked service for REST API. I created a REST API source dataset and a JSON based sink data set and a copy activity.

When I tried "Preview Data" in the copy activity, I am getting below error.

Question: Is it possible to call a Token based REST API using a service principal? If yes, how is the token acquired using SP and passed to the REST end point?

If that is not feasible, then what are my options?

Error code23353

DetailsRest call failed with client error, status code 401 Unauthorized, please check your activity settings. Request URL: https://zzz-api-management-prod.azure-api.net/ddd/GetMetadata. Response: { "statusCode": 401, "message": "AAD Auth Access token is missing or invalid." }

Activity ID3db4f555-1e29-4f0e-9b84-0d4c3b0989f1

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,549 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnnuKumari-MSFT 30,751 Reputation points Microsoft Employee
    2024-03-20T08:02:29.5033333+00:00

    Hi Anoop Jose ,

    Welcome to Microsoft Q&A platform and thanks for posting your query here.

    I understand that you are trying to call a REST API endpoint in ADF using service principal authentication. The error you are getting "AAD Auth Access token is missing or invalid" might be due to the fact that it's not correctly passed with proper syntax. In authorization header, you need to add "Authorization : Bearer <Access Token>". Kindly share the screenshot of the API call you are making.

    You can use the client ID and client secret of the service principal to authenticate and acquire the token. You can then pass this token in the Authorization header of the REST API request.

    Kindly watch out the following video to understand the steps for implementation on how to Get and use Access Token for Service Principle using REST API

    Alternatively, you can also use powershell script to get the access token . Kindly check this blogpost: Getting an access token for AzureAD using PowerShell

    Hope it helps. Kindly let us know how it goes. Thankyou

    1 person found this answer helpful.
    0 comments No comments