【问题标题】:How to add user to AzureDevOps programmatically (e.g. Rest API) without notification?如何在不通知的情况下以编程方式(例如 Rest API)将用户添加到 AzureDevOps?
【发布时间】:2020-03-10 19:18:47
【问题描述】:

我想以编程方式将用户添加到我的 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#

【问题讨论】:

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


    【解决方案1】:

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

    Rest api:需要在url中加上doNotSendInviteForNewUsers=true,使用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"}}}]
    

    我在 Postman 中的测试:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-25
      • 2014-11-11
      • 2017-11-24
      • 2011-06-16
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多