1

Is there a way to get list of test points data via Azure DevOps API?

list

I tried this powershell script

function GetUrl() {
    param(
        [string]$orgUrl, 
        [hashtable]$header, 
        [string]$AreaId
    )

    # Area ids
    # https://learn.microsoft.com/en-us/azure/devops/extend/develop/work-with-urls?view=azure-devops&tabs=http&viewFallbackFrom=vsts#resource-area-ids-reference
    # Build the URL for calling the org-level Resource Areas REST API for the RM APIs
    $orgResourceAreasUrl = [string]::Format("{0}/_apis/resourceAreas/{1}?api-preview=5.0-preview.1", $orgUrl, $AreaId)

    # Do a GET on this URL (this returns an object with a "locationUrl" field)
    $results = Invoke-RestMethod -Uri $orgResourceAreasUrl -Headers $header

    # The "locationUrl" field reflects the correct base URL for RM REST API calls
    if ("null" -eq $results) {
        $areaUrl = $orgUrl
    }
    else {
        $areaUrl = $results.locationUrl
    }

    return $areaUrl
}

$orgUrl = "https://dev.azure.com/fodservices"
$personalToken = "<my token pat>"

Write-Host "Initialize authentication context" -ForegroundColor Yellow
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = @{authorization = "Basic $token"}

Write-Host "Demo 3"

$coreAreaId = "3b95fb80-fdda-4218-b60e-1052d070ae6b"
$tfsBaseUrl = GetUrl -orgUrl $orgUrl -header $header -AreaId $coreAreaId

$relDefUrl = "$($tfsBaseUrl)/_apis/testplan/Plans/70152/Suites/70154/TestPoint?api-version=5.0-preview.2"
try {
    $output = Invoke-RestMethod -Uri $relDefUrl -Method Get -ContentType "application/json" -Headers $header

}
catch{
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription

}
$output.value | ForEach-Object {
    Write-Host $_.id
}

the result is:

Demo 3

StatusCode: 404

StatusDescription: Not Found

Can anyone tell me what i'm doing wrong im new to using powershell and azure devops rest api

3
  • What is the value of $tfsBaseUrl? It needs to include the team project. Commented Jun 12, 2021 at 0:49
  • I edited and added the function 'geturl' i used at first and the token i have + the url im using Commented Jun 12, 2021 at 1:21
  • Right, but look at the contents of that variable. It includes the organization name, but not the project name. You need to include the project name in the URL. Look at the documentation and compare your URL to the documentation's URL. Commented Jun 12, 2021 at 3:38

1 Answer 1

0

Look at the contents of the $tfsBaseUrl variable. It includes the organization name, but not the project name. You need to include the project name in the URL. Look at the documentation and compare your URL to the documentation's URL.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried : $relDefUrl = "$($tfsBaseUrl)/Training%20projects/_apis/testplan/Plans/70152/Suites/70154/TestPoint?api-version=5.0-preview.2" but same problem
Still a bit stuck in this, if there is a solution i'll welcome any help and thnx in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.