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

Update license level using Azure DevOps REST API

我正在使用 postman 进行测试,以使用 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
}

如果您想将级别更改为基本级别,而不是 "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