DEV Community

Getting started with Azure DevOps API with PowerShell

Olivier Miossec on January 26, 2020

I use Azure DevOps every day for different kinds of clients, teams, and projects. I need to set up access, whenever I need Boards, Test Plans or ot...
Collapse
 
alexia19apl profile image
alexis19apl

Hi Olivier, what an incredible and working article (tested, and yeah it works),
Could be applied this concept to Wikis, I mean to retrieve data from a wiki or the other possible case to place data a wiki?

Collapse
 
amolkhanorkar profile image
Amol Khanorkar

Hi Olivier,
I am getting error after executing below Invoke-restMethod,
Invoke-RestMethod -Uri $uriProject -Method Post -Headers $AzureDevOpsAuthenicationHeader -Body $projectConfiguration -ContentType "application/json"

Below is the error mesaage:
Invoke-RestMethod : Invalid URI: The hostname could not be parsed.
At line:1 char:1

  • Invoke-RestMethod -Uri $uriProject -Method Post -Headers $AzureDevOps ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], UriFormatException
    • FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Please help me resolve this error so I can try to create a Project and go-ahead.

Collapse
 
paulsisaac profile image
Paul isaac

I am confused as to how this works for some people. The $uriProject variable is created using the ProjectID, which is hardcoded in the script $ProjectID = "576e2e9d-c7ee-4fd5-XXXXXXXXXX". I am assuming this is not correct and it only comes further down in the script after the $UriProject is queried.
As such this line (Invoke-RestMethod -Uri $uriProject -Method get -Headers $AzureDevOpsAuthenicationHeader).value fails as there is no value for $uriProject.

Am I looking at this right, later on, further down $projectID is defined as a hardcoded variable and then $uriproject is created using the $ProjectID

$uriProject = $UriOrga + "_apis/projects/$($ProjectID)/properties?api-version=5.1-preview.1"

But how do we get the Project ID in the first place?

Collapse
 
rr9853462 profile image
Rima Sharma

Great post! This is a great starting point for anyone looking to get started with Azure DevOps API and PowerShell. The combination of cloud and DevOps is so powerful and this post does a great job of showing how to leverage them together. Highly recommend checking it out.

Collapse
 
revanthkariappa profile image
Revanth Kariappa K R • Edited

which is the default team id
System.CurrentProcessTemplateId cc94d82xxxxxxxxxdc6557bf
System.OriginalProcessTemplateId cc92xxxxxxxxxxxxxx-a22557bf
System.ProcessTemplateType b8a3a93xxxxxxxxxxxc-63e9f2
System.MSPROJ <?xml version="1.0" encoding="utf-8"?>...
System.Process Template Scrum
System.Microsoft.TeamFoundation.Team.Count 1
System.Microsoft.TeamFoundation.Team.Default e469xxxxxxxxxxxxx072f867
System.SourceControlCapabilityFlags 2
System.SourceControlGitEnabled True
System.SourceControlGitPermissionsInitialized True
System.Wiki.57985xxxxxxxxxxxxxxe53 {"id":"5xxxxxxxxxxxx06-9e53","versions":[{"Version":"wikiMaster"}],"type":0,"...

Collapse
 
arulmouzhi profile image
ARULMOUZHI

Hi Olivier Miossec,
I have followed the above things and it works well. But my case is - Delete the bulk set of test cases through PowerShell. I have also checked MS Doc reg this - docs.microsoft.com/en-us/azure/dev... . Bulk deletion is not supported at present from a query results page. So, I have to do it by using either .net or powershell. By reading the above article, i am little bit good and familiar with powershell. but it throws error for me when i tried bulk delete test case. Can you help me reg this. i have posted this as question here - stackoverflow.com/questions/620202...

Collapse
 
ayanmullick profile image
Ayan Mullick

Is it possible to pass the token in the URL? I'm trying to use a URL to create an AzMonitor Action Group Webhook that would create an ADO task when an alert is triggered. However, the webhook needs the token in the URL.

Authenticate the webhook for activity log alerts

Collapse
 
sudalaikumar1624 profile image
sudalaikumar1624

Hi
Using API, How to get the latest code from TFVC repo in Azure Devops ? Example
Thanks in advance!

Collapse
 
ravidsinghbiz profile image
Ravi D. Singh

Do you use the terraform for any azure devops automation?

Collapse
 
roua99 profile image
roua99

Hi, I had this error in the step when creating project Configuration

Invoke-RestMethod : {"count":1,"value":{"Message":"The requested resource does not support http method 'POST'."}}