mayonaes
17 days agoNew Member
Use Zephyr Scale Cloud API to add existing test cases to and newly created test cycle.
I am attempting to do this via powershell script in teamcity but I am getting a 404 when it attempts to add the testcase to the testcycle. I cannot for the life of me figure out why it is not working. any help is appreciated.
# -----------------------------
# Create test cycle
# -----------------------------
try {
$createResp = Invoke-RestMethod -Uri $TestCycleEndpoint -Method POST -Headers $headers -Body ($body | ConvertTo-Json -Depth 5)
$testCycleKey = $createResp.key
Write-Host "✅ Created Zephyr Scale test cycle: $testCycleKey (linked to $($env:ZS_LINKED_ISSUE))"
} catch {
$errResponse = $_.Exception.Response
if ($errResponse -ne $null) {
$reader = New-Object System.IO.StreamReader($errResponse.GetResponseStream())
$responseBody = $reader.ReadToEnd()
Write-Error "❌ Failed to create Zephyr Scale test cycle: $($_.Exception.Message)`nResponse: $responseBody"
} else {
Write-Error "❌ Failed: $($_.Exception.Message)"
}
exit 1
}
# -----------------------------
# Add mapped test cases to the cycle
# -----------------------------
$cycleTestCases = @()
foreach ($rxName in $TestCaseMapping.Keys) {
$cycleTestCases += @{ testCaseKey = $TestCaseMapping[$rxName] }
}
$addCasesEndpoint = "https://api.zephyrscale.smartbear.com/v2/testcycles/$testCycleKey/testcases"
$addCasesBody = @{
items = $cycleTestCases
}
try {
Invoke-RestMethod -Uri $addCasesEndpoint -Method POST -Headers $headers -Body ($addCasesBody | ConvertTo-Json -Depth 5 -Compress)
Write-Host "✅ Added $($cycleTestCases.Count) test cases into cycle $testCycleKey"
} catch {
Write-Error "❌ Failed to add test cases into cycle ${testCycleKey}: $($_.Exception.Message)"
exit 1
}