azurepowershellazure-devopsazure-rest-api

not able to delete test cases in azure devops through powershell scripts


I have checked How to delete multiple test cases in Azure DevOps

It not works for me.

Using PowerShell scripts alone, I want to delete multiple test cases in one go in Azure DevOps. Currently, portal only allows to delete one at a time.

I have tried like below way, and throws exceptions.

$url = "https://dev.azure.com/testarulmouzhie/testDemo_Project/_apis/test/testcases/21?api-version=5.0-preview.1"
Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json

it throws error like below one- enter image description here

Even tried with the new api version, same error comes-

$url = "https://dev.azure.com/testarulmouzhie/testDemo_Project/_apis/test/testcases/21?api-version=5.1-preview.1"
Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json

Attached the error for ref-

Invoke-RestMethod :
Azure DevOps
Service Status Support @AzureDevOps
At line:1 char:1
+ Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

For ref, anyway simple GET rest api calls works fine. I have tried below one and those are working fine.

$AzureDevOpsPAT = "a2wzly2bsirXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$OrganizationName = "testarulmouzhie"

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }

$UriOrga = "https://dev.azure.com/$($OrganizationName)/" 
$uriAccount = $UriOrga + "_apis/projects?api-version=5.1"

Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader

Even used fiddler and tried to capture error logs- attached those too enter image description here enter image description here


Solution

  • Ah I think you have missed your the autorizationheader in your delete Invoke API

    Please include the -Headers $AzureDevOpsAuthenicationHeader like below

    --give below your pat access token
    
    $AzureDevOpsPAT = "ukcvd42u5rXXXXXXXXXXXXXXXXXXX";
    $AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) };
    $url = "https://dev.azure.com/testarulmouzhie/testDemo_Project/_apis/test/testcases/21?api-version=5.0-preview.1"
    Invoke-RestMethod -Uri $url -Method Delete -ContentType application/json -Headers $AzureDevOpsAuthenicationHeader;
    

    As Leo suggested it also maybe with the license, so how to check your license for the test cases?

    enter image description here