sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

The to array is required for all personalization objects , and must have at least one email object with a valid email address.

Open alessandroperetti opened this issue 10 months ago • 1 comments

Hello community,

I have this payload in nodeJS and I am using @sendgrid/mail/7.6.1 library (node v.18.15.0):

{
    "from": "[email protected]",
    "to": "[email protected]",
    "templateId": "template-id",
    "personalizations": [
        {
            "to:": [
                {
                    "email": "[email protected]"
                }
            ],
            "customArgs": {
                "context": "example-string",
                "templateId": "template-id"
            },
            "dynamicTemplateData": {
                "confirmUrl": "example-url",
                "button": "example-button"
            }
        }
    ]
}

When I try to send the email I got the following issue in the response:

field: "personalizations.0.to"
help: "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.personalizations.to"
message: "The to array is required for all personalization objects, and must have at least one email object with a valid email address."

Based on the response there is a missing to in personalizations array at position 0 but it seems inconsistant because is actually present. I guess the issue does not reflect the real issue is happening behind the scene.

Do you have any idea what is wrong about it?

Cheers

alessandroperetti avatar Jan 16 '25 11:01 alessandroperetti

I solved moving customArgs in the root of the payload:

{
    "from": "[email protected]",
    "to": "[email protected]",
    "templateId": "template-id",
    "dynamicTemplateData": {
        "confirmUrl": "example-url",
        "button": "example-button"
      },
     "customArgs": {
         "context": "example-string",
         "templateId": "template-id"
      }
}

Actually I did not understand why is not working with the old structure. I leave the issue open in case someone helps to investigate.

alessandroperetti avatar Jan 16 '25 13:01 alessandroperetti