Azure DevOps Pipelines API, Object Moved error
Using curl you may find documentation to use Authorization: Basic $PAT
to pass
your personal access token (PAT).
Let’s say we want to trigger a pipeline run. This is the version you may see around. This does not work and causes a Object Moved page to be loaded with a tag. The link basically logs you into Azure DevOps.
curl --request POST --header "Content-Type: application/json" \
--header "Authorization: Basic $AZURE_RELEASE_TRIGGER_TOKEN" \
--data '{ resources: { repositories: { self: { refName: "refs/heads/master" } } } }' \
"https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1"
The issue is it’s not logging you in properly through the PAT. This could be a
PAT error or due to invalid authorization format. What works though is if you
use the user option for curl
, passing your PAT as a password (empty username).
curl --request POST \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--user ":$AZURE_RELEASE_TRIGGER_TOKEN" \
--data '{ resources: { repositories: { self: { refName: "refs/heads/master" } } } }' \
"https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1"
If successful, you should see the proper response instead of the Object Moved
error. Remember to add the :
in the user part. This is the separation format
due to the blank user. See curl --help
to see more details.