使用Azure DevOps REST API更新许可证级别

时间:2019-07-18 19:41:15

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

我正在测试使用邮递员使用REST API更新Azure DevOps中的许可证级别。我正在使用以下POST URL:

https://vsaex.dev.azure.com/sandbox-org/_apis/userentitlements/88d3bc6c-0eb1-481b-bea0-8fbf3a5e054c?api-version=5.0-preview.2

以下内容作为正文传递:

[
  {
    "from": "",
    "op": "replace",
    "path": "/accessLevel",
    "value": {
      "accountLicenseType": "basic",
      "licensingSource": "account"
    }
  }
]

我收到以下400错误的请求消息。任何解决此问题的想法。

{
    "$id": "1",
    "innerException": null,
    "message": "Value cannot be null.\r\nParameter name: userEntitlement",
    "typeName": "System.ArgumentNullException, mscorlib",
    "typeKey": "ArgumentNullException",
    "errorCode": 0,
    "eventId": 0
}

1 个答案:

答案 0 :(得分:1)

如果要将级别更改为“基本”,请使用"accountLicenseType": "basic",express代替此"accountLicenseType": "express",

但是您得到的不是它的错误,您没有编写所有尝试的脚本,因此很难发现问题,但是我成功使用此PowerShell脚本更改了级别:

$user = ""
$token = "MY-PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$url = "https://vsaex.dev.azure.com/{organization}/_apis/userentitlements/{user-Guid}?api-version=5.0-preview.2"

$body = @"
[
  {
    "from": "",
    "op": "replace",
    "path": "/accessLevel",
    "value": {
      "accountLicenseType": "express",
      "licensingSource": "account"
    }
  }
]
"@
Invoke-RestMethod -Uri $url -Method Patch -ContentType application/json-patch+json -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body