首页 > 解决方案 > 如何在不通知的情况下以编程方式(例如 Rest API)将用户添加到 AzureDevOps?

问题描述

我想以编程方式将用户添加到我的 Azure DevOps 服务组织,但他们不会收到通知。我已经开始使用User Entitlement Rest API编写如下脚本,但用户仍会收到通知:

$method = 'POST'
$devopsuri = "https://vsaex.dev.azure.com/<Devops org name>/_apis/userentitlements?api-version=5.1-preview.1"
$pat = "<pat>"
$encodedPat = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$pat"))
$header = @ {
  Authorization = "Basic $encodedPat"
}
$body = @ {
  "accessLevel" = @ {
    "accountLicenseType" = "stakeholder"
  }
  "user" = @ {
    "principalName" = "<UPN>"
    "subjectKind" = "user"
  }
} | ConvertTo - Json - Depth 5
$result = Invoke - RestMethod - Uri $devopsuri - Method $method - Headers $header - Body $body - UseBasicParsing - ContentType 'application/json'
https://stackoverflow.com/questions/ask#

标签: restazure-devopsazure-devops-rest-api

解决方案


当我们不签Send email invites入 UI 时,受邀者将不会收到通知。f12所以我们可以通过在浏览器中按下来获取这个 api 。

在此处输入图像描述

在此处输入图像描述

Rest api:需要添加doNotSendInviteForNewUsers=true到 url 和使用PATCH方法。

PATCH https://vsaex.dev.azure.com/{org}/_apis/UserEntitlements?doNotSendInviteForNewUsers=true&api-version=5.1-preview.1

示例请求正文

[{"from":"","op":0,"path":"","value":{"accessLevel":{"licensingSource":1,"accountLicenseType":2,"msdnLicenseType":0,"licenseDisplayName":"Basic","status":0,"statusMessage":"","assignmentSource":1},"user":{"principalName":"XXXX@outlook.com","subjectKind":"user"}}}]

我在邮递员中的测试:

在此处输入图像描述


推荐阅读