sendinblue / APIv3-nodejs-library

SendinBlue's API v3 Node.js Library
ISC License
101 stars 47 forks source link

Sending transactional email to many recipient fails with a 400 Bad Request response #122

Closed OneManEquipe closed 2 years ago

OneManEquipe commented 2 years ago

I'm trying to send a transactional email to a few hundred recipients, and I get this error:

{"code":"INVALID_PARAMETER","message":"Unexpected long headers length, got: 19552 want: less than 4096 chars"}

If I try the same call with fewer recipients (~50) all goes well instead.

I'm using the following version:

"sib-api-v3-sdk": "^8.3.0",

The problem arises when I run this snippet:

apiInstance.sendTransacEmail(sendSmtpEmail).then(
    (res) => {
        console.log("success", res);
    },
    (error) => {
        console.error('failure', error.response.statusCode, error.response.body);
    }
);

where apiInstance is initialized as follows:

const SibApiV3Sdk = require("sib-api-v3-sdk");
const apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();

Here is the payload I'm passing to sendTransacEmail (truncated for brevity and anonimized):

{
    "sender": {
        "email": "sender@example.com",
        "name": "My sender"
    },
    "to": [
        {
            "cognome": "Guapo",
            "nome": "Lapo 0",
            "email": "lapo.guapo.0@example.com",
            "name": "Lapo 0 Guapo"
        },
        {
            "cognome": "Guapo",
            "nome": "Lapo 1",
            "email": "lapo.guapo.1@example.com",
            "name": "Lapo 1 Guapo"
        },
        // ... omitted for brevity
        {
            "cognome": "Guapo",
            "nome": "Lapo 698",
            "email": "lapo.guapo.698@example.com",
            "name": "Lapo 698 Guapo"
        },
        {
            "cognome": "Guapo",
            "nome": "Lapo 699",
            "email": "lapo.guapo.699@example.com",
            "name": "Lapo 699 Guapo"
        }
    ],
    "templateId": 26,
    "replyTo": {
        "email": "help@example.com",
        "name": "Support - My App"
    },
    "tags": [
        "alert"
    ],
    "params": {
        // ... 
    }
}

The call fails, and the error callback is invoked, which prints the following:

failure 400 {code: 'INVALID_PARAMETER', message: 'Unexpected long headers length, got: 31278 want: less than 4096 chars'}

As I said, if I instead use 40-50 recipients the operation succeeds.

Can you help me?

OneManEquipe commented 2 years ago

For anyone encountering this problem, I got feedback from the Sendinblue official support, who in turn checked with their API team, there is actually a limit to 99 recipients, which in turn caused my error.

Closing the issue