1

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

Can anyone help to solve this? Thanks in advance.

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

Arulmouzhi
  • 1,878
  • 17
  • 20
  • It says in the message, "Azure DevOps Service Status Support @AzureDevOps". Do any other REST calls work for you? Perhaps a simple `GET`? – Ash May 26 '20 at 10:49
  • @Ash ,Yup, simple GET works like a charm! – Arulmouzhi May 26 '20 at 11:07
  • You can post it as answer to close this issue. – Joey Cai May 26 '20 at 11:29
  • @JoeyCai, mentioned Get already works, but Delete throws error and i want to do Delete call. – Arulmouzhi May 26 '20 at 11:31
  • Does the `DELETE` work if you use the [latest version of the API](https://learn.microsoft.com/en-us/rest/api/azure/devops/test/test%20cases/delete?view=azure-devops-rest-5.1) too? I see your example of the `GET` is for 5.1. If not, is possible that you do not have the permissions to use this method or call this API? Please try with the latest version and post the full error in codeblocks rather than a screenshot. – Ash May 26 '20 at 12:10
  • Check the pat token is created with the sufficient permission that include delete test case permissions. – Jayendran May 26 '20 at 12:56
  • Yup, Pat token is created with full access. – Arulmouzhi May 26 '20 at 13:09
  • @Ash, posted full error details details and used the latest version. Microsoft doc link has http version alone. – Arulmouzhi May 26 '20 at 13:12

2 Answers2

2

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

It seems you do not have the Test Plans license to use the REST API Test Cases - Delete.

Azure Test Plans uses an access level called Basic + Test Plans, you need a Basic + Test Plans license to manage the test plans and test suites, etc. Please check the following link:

Manual test permissions and access

enter image description here

Here are two ways of ensuring you have the right license.

1) The user is assigned a test manager extension license - https://marketplace.visualstudio.com/items?itemName=ms.vss-testmanager-web

2) The user has a VS Enterprise or Test Professional subscription

You can do this by accessing test hub and trying to add test cases directly there with the same user (account create the PAT)as is used in the REST API.

Check this thread for some details.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Hi Leo, I have fully checked all your valuable points mentioned above. Here in my scenario, I have Basic + Test Plans License and i am admin of my account. Also i have given full access for Personal Access Token-PAT Created. Even the accesses i am having all, facing issue like above when running delete scripts in powershell. I am not familiar with powershell scripts, so i doubt that ,thinking may be i have issues in my powershell scripts but not sure reg real reason behind the error. – Arulmouzhi May 27 '20 at 13:50
1

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

Jayendran
  • 9,638
  • 8
  • 60
  • 103
  • Thanks! It Solves the issue. I have added Authorization header and also started trial of Basic + test Plans. So now it is working! – Arulmouzhi May 28 '20 at 07:38