Skip to content

sendTransacEmail does not allow cc to be an empty array #90

Description

@cashc

Hi there, we've just started using the brevo-node client for sending transactional emails in our web app and encountered an unexpected behavior in the sendTransacEmail function

body: ObjectSerializer.serialize(sendSmtpEmail, "SendSmtpEmail")
where it throws an error when the cc field of the sendSmtpEmail parameter is an empty array.

It took us some time to debug the issue and make this fix where we must explicitly pass cc: false or cc: undefined instead of cc: [].

Before:

const cc: TEmail[] = [];
if (otherUser.isActive) {
  cc.push({ email: otherUser.email });
}
...
return {
    to: [{ email: recipientUserEmail }],
    cc,
};

After:

...
return {
    to: [{ email: recipientUserEmail }],
    ...(cc.length > 0 && { cc }), // the fix
  };

This is a strange behavior to have since the typescript type specify that cc is an array. We think you should allow an empty array to be passed so what happened to us today doesn't happen to others in the future.

Merci!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions