I have service principal account created in azure cloud for azure devops pipeline URL. how do I make a rest call to the url?

227 Views Asked by At

I have the follwing url for triggering azure devops pipiline url https://dev.azure.com/xxx/xxx/xxx.This url registered in azure cloud service principal account. previously I used pat token for authentication. now I want to use service principal account. I have clint id and cliend secret of the service principal account. Now How can I make call to the pipeline url through post man or using logic apps. any documentation or something will be really helpfull for me.

1

There are 1 best solutions below

2
jinkc-MSFT On

You can use curl to make a rest call to the url. You can learn more about curl in the link.

Since you have service principal account created,

First you need to request the Access Token.

curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' 
https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token 
-d 'client_id=<client-id>' 
-d 'grant_type=client_credentials' 
-d 'scope=<scope.default>' 
-d 'client_secret=<client-secret>'

Then you can call Azure REST API using Bearer Token to be authorized:

curl -X GET \
    -H 'Authorization: Bearer <access-token>' \
    https://{instance}/{collection}/{team-project}/_apis/{area}/{resource}?api-version={version}