Forum Discussion

Santosh1986's avatar
Santosh1986
Copper Contributor
Jul 19, 2023

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/send-mail/send-mail?view=azure-devops-rest-7.0#sendmailbody"

 

Can anybody suggest what should be the request body parameters for the API Call.

My Implementation:

API CALL (POST) : https://dev.azure.com/{{organisation}}/{{project}}/_apis/wit/sendmail?api-version=7.0

Request Body:

{
  "fields": "test",
  "ids": 1,
  "message": {
    "body": "Test mail",
    "subject": "testsubject",
    "to": "email address removed for privacy reasons"
  },
  "clientRecipients": "email address removed for privacy reasons"
}

Response:

{
    "$id": "1",
    "innerException": null,
    "message": "Value cannot be null.\r\nParameter name: clientRecipients",
    "typeName": "System.ArgumentNullException, mscorlib",
    "typeKey": "ArgumentNullException",
    "errorCode": 0,
    "eventId": 0
}

2 Replies

  • Smokovsky's avatar
    Smokovsky
    Copper 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)

     

  • xxxmatko's avatar
    xxxmatko
    Copper Contributor
    I've got the same error. There is nothing about the 'clientRecipients' parameter in the documentation. Please help.

Resources