Reputation: 3649
I want to add users to my Azure DevOps Services Organization programatically without them getting notifications. I've started with a script like below using the User Entitlement Rest API but users still get notifications:
$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#
Upvotes: 0
Views: 654
Reputation: 19381
When we don’t check Send email invites
in UI, invitees will not receive notification.
So we can grab this api by pressing f12
in the browser.
Rest api: need to add doNotSendInviteForNewUsers=true
to the url and use PATCH
method.
PATCH https://vsaex.dev.azure.com/{org}/_apis/UserEntitlements?doNotSendInviteForNewUsers=true&api-version=5.1-preview.1
Sample request body:
[{"from":"","op":0,"path":"","value":{"accessLevel":{"licensingSource":1,"accountLicenseType":2,"msdnLicenseType":0,"licenseDisplayName":"Basic","status":0,"statusMessage":"","assignmentSource":1},"user":{"principalName":"[email protected]","subjectKind":"user"}}}]
My test in Postman:
Upvotes: 2