尝试通过API更新VSTS上的测试用例状态时遇到未授权的问题

时间:2019-09-13 09:19:44

标签: api azure-devops azure-devops-rest-api

我们重复了下面提到的相同步骤。 Update VSTS test case status to PASS / FAIL using rest api

但是,我们得到的是401或404或203响应代码。您能帮我们吗?

  1. 使用VSTS Webtest的方法

    https:// {组织代码} .visualstudio.com / {项目代码} / _ api / _testManagement / BulkMarkTestPoints?api-version = 5.1-preview.1

有效载荷:

{
 planId: 187830,
 suiteId: 187831,
 testPointIds: [88212],
 outcome: 2
 }

Headers:
Referer=https://{Organisation Code}.visualstudio.com/{ProjectName}/_testManagement
accept=application/json
accept-language=en-US
Authorization=Basic {PAT}
Host={Organisation Code}.visualstudio.com
content-type=application/json

响应:

HTTP/1.1 401 Unauthorized
Pragma : no-cache
Content-Length : 307
Content-Type : application/json; charset=utf-8
Expires : -1

方法2:使用POSTMAN

https://{Organisation Code}.visualstudio.com/{Project Code}/_api/_testManagement/BulkMarkTestPoints?api-version=5.1-preview.1

有效载荷:

{
 planId: 187830,
 suiteId: 187831,
 testPointIds: [88212],
 outcome: 2
 }

Headers:
Referer=https://{Organisation Code}.visualstudio.com/{ProjectName}/_testManagement
accept=application/json
accept-language=en-US
Authorization=Basic {PAT}
Host={Organisation Code}.visualstudio.com
content-type=application/json

注意:我们已将凭据授予为基本身份验证,并且遇到相同的错误。

HTTP/1.1 401 Unauthorized
Pragma : no-cache
Content-Length : 307
Content-Type : application/json; charset=utf-8
Expires : -1

1 个答案:

答案 0 :(得分:0)

您在上述线程中提到的步骤似乎不包含身份验证。您可以在powershell脚本中参考以下完整示例。

$url = "xxxxxxxxxxxx" # Request url
$connectionToken="xxxxxxxxxxxxxxxxxxxxxxxxx" # personal access token

$base64AuthInfo=  [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))

$pipeline = Invoke-RestMethod -Uri $url -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get

要获取您的个人访问令牌,可以检查步骤here