sendinblue / APIv3-nodejs-library

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

Enhancement request - constructors #49

Closed nstuyvesant closed 3 years ago

nstuyvesant commented 5 years ago

Per @ekta-slit, this is an example of how to send a transactional email:

var SibApiV3Sdk = require('sib-api-v3-sdk');

var defaultClient = SibApiV3Sdk.ApiClient.instance;
var apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = "YourApiV3Key"

var apiInstance = new SibApiV3Sdk.SMTPApi();

var sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail(); // SendSmtpEmail | Values to send a transactional email

sendSmtpEmail.to = [{ "email":"to@domain.com", "name":"toName"}];
sendSmtpEmail.sender = { "email":"sender@domain.com", "name":"sender"};
sendSmtpEmail.htmlContent = "This is test content";
sendSmtpEmail.subject = "My Subject";
sendSmtpEmail.headers = {"x-mailin-custom":"myV3Custom" };
sendSmtpEmail.tags = ["myTag1","myTag2"];
sendSmtpEmail.attachment =  [{"url": "https://example.com/ValidimageUrl1.jpg"},{"url": "https://example.com/ValidimageUrl2.jpg"}]

apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
  console.log('API called successfully. Returned data: ' + data);
}, function(error) {
  console.error(error);
});

Would like to request support for a constructors like this:

let sendSmtpEmail =  new SibApiV3Sdk.SendSmtpEmail({
    to: [{ email: 'to@domain.com', name: 'toName'}],
    sender: { email: 'sender@domain.com', name: 'sender'},
    htmlContent: 'This is test content',
    subject: 'My Subject',
    tags: ['myTag1', 'myTag2']
  });

Thanks, Nate

shubhamUpadhyayInBlue commented 3 years ago

Hi @nstuyvesant

You can pass the payload as a simple JSON for the /smtp/email route.


let defaultClient = SibApiV3Sdk.ApiClient.instance;

let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'YOUR_API_KEY';

let apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();

let sendSmtpEmail = {
    "subject": "My {{params.subject}}",
    "htmlContent": "<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>",
    "sender": {"name":"John Doe","email":"example@example.com"},
    "to": [{"email":"example@example.com","name":"Jane Doe"}],
    "cc": [{"email":"example@example.com","name":"Janice Doe"}],
    "replyTo": {"email":"example@example.com","name":"John Doe"},
    "headers": {"Some-Custom-Name":"unique-id-1234"},
    "params": {"parameter":"My param value","subject":"New Subject"}
};

apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
  console.error(error);
});```

Thanks,
Shubham