Azure DevOps: API vs. AZ CLI


If you have stumbled upon this blog post, you are likely trying to decide which is the better choice. I’m going to give you that answer right now. The answer is Both. Let me explain.

Azure DevOps has a robust API working behind the scenes and it can be utilized to an extent that even I haven’t fully explored. As for the AZ DevOps CLI, that is a near 1:1 to the API. There are still some parts of it that are under development, but they will surely be a perfect match soon.

What is an API? The API or Application Programming Interface is essentially a middleman between a data source and an application. This application could be as simple as a monitoring system or PowerShell Module (link down below). What is a CLI? A CLI is short for Command-line Interface. This has been around since the dawn of computers. Easiest example would be the Windows System CLI that you likely interact with occasionally to check an IP configuration or trace out a network route.


Let’s look at pros and cons

Azure DevOps API


  • Robust documentation
  • Easy to use in many scripting and development languages
  • Can accomplish just about any task you think of


  • The Documentation doesn’t always lead you in the right direction when creating your JSON package for a put or patch
  • Some features, even though they are shown, aren’t available YET
  • Must pay attention to the URI carefully because they change depending on what you are interacting with

Azure DevOps CLI


  • Robust documentation
  • Can be easier to understand than the API
  • Easy to use in many scripting and development languages
  • Clearly shows where it’s limits are
  • Some tasks are simplified


  • Doesn’t have all the functionality that the API has

API vs CLI Demo

Warning: All Demonstrations will be done with PowerShell

In this demonstration, I am going to do three examples of how the API and CLI compare.

To install Azure CLI go here.

To install Azure DevOps extension for AZ CLI run this command: az extension add –name azure-devops

Before we start, we need to know how to auth to both of these methods.

Azure DevOps API

For the API we just need to create a header. The final result looks like this as a parameter:

-Headers @{Authorization=(“Basic {0}” -f $base64AuthInfo)}

To get to this we need to create that $base64AuthInfo package.

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((“{0}:{1}” -f $ADOUser,$ADOpat)))

Two pieces of information that will be needed are the $ADOuser and the $ADOpat. The $ADOuser will actually be a blank string ($ADOuser = “”). The $ADOpat is your Personal Access Token that you would create from the Azure DevOps site. You can follow the instructions on this site to do that. Once you set those two variables then you run the $base64AuthInfo line above and you are good to go.

Azure DevOps CLI

For this one you have a one line login to perform.

$PAT | Az devops login –org $ADOorg

$PAT is your Personal Access Token for Azure DevOps.  You can follow the instructions on this site to create a new one. And $ADOorg is your Azure DevOps Organization name. You can find this in the URL here: Set those two variables and you are good to run the line above.


Throughout these examples I have used variables for a couple things to make it more universal. Two of the main variables are $ADOaccount and $ADOprojectname. These represent the Organization Name and Project respectively. Set these as a variable now to easily follow along.


#1 Get a Release Definition and Update it

Azure DevOps API

You start by having to either know what definition ID you want to focus on or you can find the ID programmatically. The Definition ID is found in the URI of the Release Definition if you want to use your preferred browser to find it.

Definitions – Get – REST API (Azure DevOps Release) | Microsoft Docs


Azure DevOps CLI

This first step is where the CLI beats the API. You are able to just find the definition you want without having to know the ID as long as you know what the name is. All commands are assuming that you have setup your default Org and Project.

And that is all you can do. You can create a brand new release definition from here but to Update a current one is not a function right now.

#2 Create a Service Endpoint

Azure DevOps API

Azure DevOps CLI

This one isn’t as simple. To start you first have to create a service endpoint on the UI. This will serve as a template for all others like it. Follow the instructions on the link above to create your configuration file. A suggestion on how to move forward with this would be to tokenize the file to then replace values where needed using your command line.

#3 Get a Run from a Pipeline Definition

Azure DevOps API

Azure DevOps CLI

Here is a link to a great PowerShell Azure DevOps Module –


Share Post:

Stay Connected

More Articles

Microsoft Ignite 2021: a catalyst for digital transformation

The past year and a half have presented tremendous challenges for organizations around the globe and across all industries. As a result, digital transformation has never been more urgent. The innovation on display at the autumn session of Microsoft Ignite

Five tips to avoid a post-migration sticker shock

Here at the Cognizant Microsoft Business Group, I am a cross-functional leader who both manages a team dedicated to data center migration consulting and oversees our Azure cost optimization offering. Due to the nature of these roles, I live in