Skip to main content

NodeJS SDK for Sendlix API

This SDK enables the integration of the Sendlix API into NodeJS applications. It provides clients for email sending, group management, and other functionalities.

Installation

Install the SDK via npm:

npm install sendlix

Getting Started

Import the SDK into your project:

import { EmailClient, GroupClient, IAuth } from "sendlix";

Authentication

The SDK uses an API key for authentication. The API key must be in the format secret.keyId (When you copy it from the dashboard, it's already in the correct format). There are two options:

  1. Passing an API key string:

    const emailClient = new EmailClient("sk_xxxxxxxxx.xxx");
  2. Using an IAuth instance:

    import { Auth } from "sendlix";
    const auth: IAuth = new Auth("sk_xxxxxxxxx.xxx");
    const emailClient = new EmailClient(auth);
    const groupClient = new GroupClient(auth);

We recommend using the second option when you want to use both clients. This way, the auth token is only requested once and passed to both clients.

Available Clients

EmailClient

The EmailClient allows you to send emails, both standardized emails and pre-formatted EML messages.

Methods

GroupClient

The GroupClient allows you to add email addresses to groups or remove them from groups.

Methods

Examples

Sending an Email

import { EmailClient } from "sendlix";

// Initialize client
const client = new EmailClient("sk_xxxxxxxxx.xxx");

// Email configuration
const sendMail = {
from: { email: "sender@example.com", name: "Sender Name" },
to: [{ email: "recipient@example.com", name: "Recipient Name" }],
subject: "Hello World!",
html: "<h1>Welcome!</h1><p>This is a test email.</p>",
};

// Send email
client
.sendEmail(sendMail)
.then((response) => {
console.log("Email sent:", response);
})
.catch((error) => {
console.error("Error sending email:", error);
});

Adding an Email to a Group

import { GroupClient } from "sendlix";

// Initialize client
const groupClient = new GroupClient("sk_xxxxxxxxx.xxx");

groupClient
.insertEmailIntoGroup("groupId123", "recipient@example.com")
.then((success) => {
console.log("Email added to group:", success);
})
.catch((error) => {
console.error("Error adding email to group:", error);
});