如何在没有通知的情况下以编程方式将用户添加到 AzureDevOps(例如 Rest API)?
How to add user to AzureDevOps programmatically (e.g. Rest API) without notification?
我想以编程方式将用户添加到我的 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://whosebug.com/questions/ask#
如果我们不勾选 UI 中的 Send email invites
,受邀者将不会收到通知。
所以我们可以通过在浏览器中按 f12
来获取这个 api。
休息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 中的测试:
我想以编程方式将用户添加到我的 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://whosebug.com/questions/ask#
如果我们不勾选 UI 中的 Send email invites
,受邀者将不会收到通知。
所以我们可以通过在浏览器中按 f12
来获取这个 api。
休息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 中的测试: