Martin
Martin

Reputation: 130

Use the Azure DevOps WorkItemTracking sendmail

I am trying to use the sendmail functionality of the Azure DevOps WorkItemTracking api; but get the error "Value cannot be null. Parameter name ClientRecipients"

It's not a field in the API - so frankly I'm lost.. https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/send-mail/send-mail?view=azure-devops-rest-7.1

Response

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

Source code

    const sessionToken = await VSS.getAccessToken();
    const authToken = authTokenManager.getAuthorizationHeader(sessionToken);
    
    $.ajax({
        type: 'POST',
        url: `https://dev.azure.com/${organization}/${project}/_apis/wit/sendmail?api-version=7.1-preview.1`,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({
            message: {
                body: 'Hello World',
                subject: 'My email',
                to: {
                    tfIds: ['my-profile-id']
                }
            },
            projectId: project
        }),
        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', authToken);
        },
        success: (e) => {
            console.log(e);
        },
        error: (e) => {
            console.error(e);
        }
    });

(updated to include token code)

Upvotes: 2

Views: 881

Answers (1)

Chris
Chris

Reputation: 240

I found through experimentation that the API requires the "cc" field to be present:

"message": {
    "body" : "Test Body",
    "cc" : {},
    "to" : {
        "tfsIds" : ["xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"],
    },
    "replyTo" : {},
    "subject" : "Test Subject"
}

Upvotes: 3

Related Questions