Forum Discussion
Santosh1986
Jul 19, 2023Copper Contributor
Value cannot be null.\r\nParameter name: clientRecipients
-1 I am getting "Value cannot be null.\r\nParameter name: clientRecipients" error while trying to send email from ADO. Reference: "https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/...
Smokovsky
Nov 13, 2023Copper Contributor
Santosh1986
The error message is rather ambiguous here, but it actually means you don't have a valid recipient represented by tfids.
A working PowerShell example would be:
Invoke-RestMethod `
-Method Post `
-Uri "https://dev.azure.com/$orgName/$projectName/_apis/wit/sendmail?api-version=7.2-preview.1" `
-Headers @{
Authorization = "Bearer $accessToken"
"Content-Type" = "application/json"
} `
-Body (@{
# requires at least one workitem id, integer
ids = @($wiid)
fields = @("System.Id")
message = @{
subject = $subject
body = $body
to = @{
# if not provided, then clientRecipient missing error
# note you can get the recipient id of your orgnization from:
# https://vsaex.dev.azure.com/<your_org>/_apis/userentitlements?api-version=6.0-preview.3
# just use a GET request with authorization header
tfIds = @($recipientId)
}
# yes, both cc and replyTo are required
# but you can use an empty object
cc = @{}
replyTo = @{}
}
} | ConvertTo-Json -Depth 5)