sendinblue / APIv3-nodejs-library

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

"sender is missing" on sendTransacEmail with template #63

Closed aorsten closed 5 years ago

aorsten commented 5 years ago

I'm trying to send a transactional email based on a template. My template ID is # 1, and I am able to view the template by using:

    const apiInstance = new SibApiV3Sdk.SMTPApi();

    apiInstance.getSmtpTemplate(1).then(function(data) {
        console.log(data);
      }, function(error) {
        console.error(error);
      });

However, when trying to send using sendTransacEmail, I get an error: {"code":"missing_parameter","message":"sender is missing"}. Here is the code:

    const apiInstance = new SibApiV3Sdk.SMTPApi();

    const sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail({
        to: [{
            email: 'my@domain.com'
        }],
        templateId: 1,
        params: {
            ...
        }
    });
    const sendMail = await apiInstance.sendTransacEmail(sendSmtpEmail).then(
        data => data
    ).catch(err => {
        console.error(err)
    });

This gives the error:

{ Error: Bad Request
    at Request.callback (...\node_modules\sib-api-v3-sdk\node_modules\superagent\lib\node\index.js:688:13)
    at ...\node_modules\sib-api-v3-sdk\node_modules\superagent\lib\node\index.js:891:18
    at IncomingMessage.<anonymous> (...\node_modules\sib-api-v3-sdk\node_modules\superagent\lib\node\parsers\json.js:17:7)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1129:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  status: 400,
  response:
   Response {...
     res:
      IncomingMessage {...
        text: '{"code":"missing_parameter","message":"sender is missing"}' },
     request:
      Request {...
        method: 'POST',
        url: 'https://api.sendinblue.com/v3/smtp/email',
        ...
        protocol: 'https:',
        host: 'api.sendinblue.com',},
...

According to the API, I think using a templateId means that a sender does not need to be set. I have even tried to explicitly set a sender, but I still get the same error message.

Is this an error with the node package, the API, with my sendinblue setup, or something else?

aorsten commented 5 years ago

I was able to solve it, after reading #62 . I needed to write the parameters for the email as:

    const sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail();
    sendSmtpEmail.to = [{email: 'my@domain.com'}];
    sendSmtpEmail.templateId = 1;
    sendSmtpEmail.params = {
        ...
    };

I completely second the sentiment in #62 , as I struggled for a long while before accidentally reading #62.

tboulis commented 4 years ago

This issue shouldn't be closed... The apidocs are misleading...

mariostasos commented 4 years ago

This is not written in any part of the documentation, it would be helpful to update the docs.

MaloRchrd commented 4 years ago

yes same error here. should be re-open i have been searching for hours because of this.

Information is different depending on wich doc you look at -->

https://developers.sendinblue.com/reference#smtp-1 not the same as here https://developers.sendinblue.com/docs/send-a-transactional-email

To be fare i tried as @aorsten aorsten mentioned and still got the error

vincenzodomina commented 1 year ago

Unfortunately this is still an issue when using the new client @getbrevo/brevo and the code snippet described here: https://developers.brevo.com/recipes/send-transactional-emails-in-nodejs

I got the mentioned error "Sender is missing" by passing the email parameters into the constructor directly, and to solve it had to assign them afterwards like this:

const sendSmtpEmail = new Brevo.SendSmtpEmail(); Object.keys(emailDetails || {}).map(key => { sendSmtpEmail[key] = emailDetails[key]; });

TylerPohn commented 4 months ago

Unfortunately this is still an issue when using the new client @getbrevo/brevo and the code snippet described here: https://developers.brevo.com/recipes/send-transactional-emails-in-nodejs

I got the mentioned error "Sender is missing" by passing the email parameters into the constructor directly, and to solve it had to assign them afterwards like this:

const sendSmtpEmail = new Brevo.SendSmtpEmail(); Object.keys(emailDetails || {}).map(key => { sendSmtpEmail[key] = emailDetails[key]; });

Thank you @vincenzodomina this is exactly what I needed