Azure DevOps has a REST API: https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-7.1
How do I access it using curl.exe or PowerShell without additional support libraries?
CodePudding user response:
This instructions are for Windows, although they can be used in other platforms with slight modification.
Below, replace with your own values for:
{organization}
{project}
{team}
{pat}
You can create a PAT in your organization's portal. Using your browser, go to: (replace {organization}
):
https://dev.azure.com/{organization}/_usersSettings/tokens
Using Command Prompt
If using Command Prompt (cmd.exe), curl.exe
can be used. It is part of Windows (10 ). Also works in PowerShell, but you have to spell out curl.exe
, not just curl
. The commands below output the results to the console. You can pipe it to a file, or use the -o
option in curl to specify a file to output to.
Using PoowerShell
If using PowerShell, you use the Invoke-RestMethod
command. In the below commands, the result of the command is placed in a variable, $result
, which you can use after the invocation.
The commands below also assume variables $pat
and $header
are initialized as follows:
$pat = "{pat}"
$header = @{authorization = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)")))"}
Example getting a work item by ID (Work Items - Get Work Item):
Using curl:
curl.exe -u :{pat} -H "Content-Type: application/json" https://dev.azure.com/{organization}/_apis/wit/workItems/{id}
Using PowerShell:
$url = "https://dev.azure.com/{organization}/_apis/wit/workItems/{id}"
$entries = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" -Headers $header
Quick display of the above output:
$entries.Fields | Format-Table system.workitemtype, system.title