1
votes

I am testing using postman to update the license level in Azure DevOps using REST API. I am using the below POST URL:

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

The following is passed as body:

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

I am getting the below 400 bad request message. Any ideas to fix the issue.

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

1 Answers

1
votes

If you want to change the level to Basic, instead of this "accountLicenseType": "basic", use express: "accountLicenseType": "express",.

But the error you got it's not about it, you didn't write all the script you tried so it's hard to find the issue, but I success to change the level with this PowerShell script:

$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