Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MirKml
Last active January 9, 2023 13:48
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MirKml/305fbde56db7c079d5ff96c1cad36676 to your computer and use it in GitHub Desktop.
Save MirKml/305fbde56db7c079d5ff96c1cad36676 to your computer and use it in GitHub Desktop.
Azure devops API curl queries
  1. Gets PAT - personal access token - from azure devops profile. See more on this page.
    You can use username:password from 'Alternate credentials', which is also in your profile.

  2. Use curl with -s - silent, doesn't print statistics. Use jq tool for pritty print json content.

> curl -s -u username:PAT -H "Content-Type: application/json" https://dev.azure.com/<organization>/_apis/projects?api-version=2.0 | jq

You can use authorization header directly from the bash tasks from some build/release pipeline with System.AccessToken pipeline variable

> curl -H "Authorization: Bearer $(System.AccessToken)" -H "Content-Type: application/json" \
   https://dev.azure.com/<organization>/_apis/projects?api-version=2.0 | jq

Some useful queries:

Get build tags for particular builds

> curl -s -u username:PAT \
  -H "Content-Type: application/json" \
  https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/tags?api-version=5.1 | jq
@ahoeing
Copy link

ahoeing commented Jul 15, 2021

What do I have to put in the $(System.AccessToken) variable?

> curl -s -u username:PAT -H "Content-Type: application/json" https://dev.azure.com/<organization>/_apis/projects?api-version=2.0 | jq

works fine, but I do not manage to invoke azure devops api with bearer token.

@jikuja
Copy link

jikuja commented Nov 27, 2022

To use bearer token: -H "Authorization: Bearer $token" or -H "Authorization: Bearer $(System.AccessToken)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment