⚠️ Important Notice: This is the current stable version but we are currently working on rebuilding our Node library from scratch.
Brevo's API exposes the entire Brevo features via a standardized programmatic interface. Please refer to the full documentation to see all the supported operations.
Brevo's API matches the OpenAPI v2 definition. The specification can be downloaded here.
Our current library is not fully compatible with all modern Node.js and TypeScript environments. To help you integrate Brevo into your applications, we're providing both plain Node.js and TypeScript-specific implementation approaches below while we work on the next generation of our SDK.
npm i @getbrevo/brevo --saveimport { TransactionalEmailsApi, SendSmtpEmail } from "@getbrevo/brevo";let emailAPI = new TransactionalEmailsApi();
emailAPI.authentications.apiKey.apiKey = "xkeysib-xxxxxxxxxxxxxxxxxxxxx"let message = new SendSmtpEmail();
message.subject = "First email";
message.textContent = "Hello world!";
message.sender = { name: "John Doe", email: "[email protected]" };
message.to = [{ email: "[email protected]", name: "Jane Smith" }];emailAPI.sendTransacEmail(message)emailAPI.sendTransacEmail(message).then(res => {
console.log(JSON.stringify(res.body));
}).catch(err => {
console.error("Error sending email:", err.body);
});npm i @getbrevo/brevo --saveimport { CreateContact, ContactsApi } from "@getbrevo/brevo";let contactAPI = new ContactsApi();
contactAPI.authentications.apiKey.apiKey = "xkeysib-xxxxxx"let contact = new CreateContact();
contact.email = "[email protected]";
contact.attributes = {
FIRSTNAME: "Alice",
LASTNAME: "Johnson",
};contactAPI.createContact(contact).then(res => {
console.log(JSON.stringify(res.body));
}).catch(err => {
console.error("Error creating contact:", err.body);
});We recommend using the following TypeScript configuration for optimal compatibility:
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src"]
}npm i @getbrevo/brevo --saveimport { TransactionalEmailsApi, SendSmtpEmail } from "@getbrevo/brevo";let emailAPI = new TransactionalEmailsApi();
(emailAPI as any).authentications.apiKey.apiKey = "xkeysib-xxxxxxxxxxxxxxxxxxxxx";let message = new SendSmtpEmail();
message.subject = "First email";
message.textContent = "Hello world!";
message.sender = { name: "Bob Wilson", email: "[email protected]" };
message.to = [{ email: "[email protected]", name: "Sarah Davis" }];emailAPI.sendTransacEmail(message)emailAPI
.sendTransacEmail(message)
.then((res) => {
console.log(JSON.stringify(res.body));
})
.catch((err) => {
console.error("Error sending email:", err.body);
});npm i @getbrevo/brevo --saveimport { CreateContact, ContactsApi } from "@getbrevo/brevo";let contactAPI = new ContactsApi();
(contactAPI as any).authentications.apiKey.apiKey = "xkeysib-xxxxxxxxx"let contact = new CreateContact();
contact.email = "[email protected]";
contact.attributes = {
FIRSTNAME: { value: "Michael" },
LASTNAME: { value: "Brown" },
};contactAPI.createContact(contact).then(res => {
console.log(JSON.stringify(res.body));
}).catch(err => {
console.error("Error creating contact:", err.body);
});Important
There has been a change in the usage of this library after v3.0.0 which is not backward compatible.
npm i @getbrevo/brevo --save
import { CreateContact, ContactsApi } from "@getbrevo/brevo";
let contactAPI = new ContactsApi();
(contactAPI as any).authentications.apiKey.apiKey = "xkeysib-xxxxxxxxx";
contact.email = "[email protected]";
contact.attributes = {
FIRSTNAME: { value: "Michael" },
LASTNAME: { value: "Brown" }
};
console.log(JSON.stringify(res.body));
}).catch(err => {
console.error("Error creating contact:", err.body);
});
import { TransactionalEmailsApi, TransactionalEmailsApiApiKeys } from '@getbrevo/brevo';
const transactionalEmailsApi = new TransactionalEmailsApi();
transactionalEmailsApi.setApiKey(TransactionalEmailsApiApiKeys.apiKey, 'xkeysib-API_KEY');
async function sendTransactionalEmail() {
try {
const result = await transactionalEmailsApi.sendTransacEmail({
to: [
{ email: '[email protected]', name: 'John doe' },
],
subject: 'Hello from Brevo SDK!',
htmlContent: '<h1>This is a transactional email sent using the Brevo SDK.</h1>',
textContent: 'This is a transactional email sent using the Brevo SDK.',
sender: { email: '[email protected]', name: 'John doe' },
});
console.log('Email sent! Message ID:', result.body.messageId);
} catch (error) {
console.error('Failed to send email:', error);
}
}
sendTransactionalEmail(); import { DealsApi, DealsApiApiKeys } from '@getbrevo/brevo';
const dealsApi = new DealsApi();
dealsApi.setApiKey(DealsApiApiKeys.apiKey, 'xkeysib-YOUR_API_KEY');
async function getDeals() {
try {
const response = await dealsApi.crmDealsGet()
console.log('Deals info:', response.body);
} catch (error) {
console.error('Failed to get account info:', error);
}
}
getDeals();import { AccountApi, AccountApiApiKeys } from '@getbrevo/brevo';
const accountApi = new AccountApi();
accountApi.setApiKey(AccountApiApiKeys.apiKey, 'xkeysib-YOUR_API_KEY');
async function getAccount() {
try {
const response = await accountApi.getAccount();
console.log('Account info:', response.body);
} catch (error) {
console.error('Failed to get account info:', error);
}
}
getAccount();import { ContactsApi, ContactsApiApiKeys } from '@getbrevo/brevo';
const contactsApi = new ContactsApi();
contactsApi.setApiKey(ContactsApiApiKeys.apiKey, 'xkeysib-YOUR_API_KEY');
async function getContacts(limit: number, offset: number) {
try {
const result = await contactsApi.getContacts(limit, offset);
console.log('Contacts:', result.body);
} catch (error) {
console.error('Failed to get contacts:', error);
}
}
getContacts(10, 0); // Example: get first 10 contacts For questions and support, please refer to our documentation or contact our support team.
This SDK is distributed under the MIT License.