A comprehensive Node.js client for interacting with the Lemn email marketing API, providing easy access to email list management, broadcasts, transactional emails, and more.
Install the package using npm:
npm install lemn-api
const LemnAPI = require('lemn-api');
// Initialize the client with your API key
const lemn = new LemnAPI('your_api_key');
// Example: Working with Lists
async function exampleListOperations() {
try {
// Create a new list
const newList = await lemn.lists.create('Marketing Contacts');
console.log('New list created:', newList);
// Add a single contact to a list
const contact = {
email: 'john.doe@example.com',
first_name: 'John',
last_name: 'Doe'
};
const addedContact = await lemn.lists.addSingleContact(newList.id, contact);
console.log('Added contact:', addedContact);
} catch (error) {
console.error('Error:', error);
}
}
const LemnAPI = require('lemn-api');
const lemn = new LemnAPI(apiKey, options);
-
apiKey
(required): Your Lemn API key -
options
(optional):-
baseUrl
: Custom base URL (defaults to Lemn's API endpoint)
-
-
lemn.lists.create(name)
: Create a new contact list -
lemn.lists.getAll()
: Retrieve all lists -
lemn.lists.get(id)
: Get a specific list by ID -
lemn.lists.update(id, updatedData)
: Update a list -
lemn.lists.delete(id)
: Delete a list -
lemn.lists.export(id)
: Export a list -
lemn.lists.addData(id, csvData)
: Add data to a list via CSV -
lemn.lists.addSingleContact(listId, contact)
: Add a single contact to a list -
lemn.lists.getDomainStats(listId)
: Get domain statistics for a list -
lemn.lists.deleteDomains(listId, domains)
: Delete specific domains from a list -
lemn.lists.deleteContacts(listId, emails)
: Delete contacts from a list -
lemn.lists.addUnsubscribes(listId, emails)
: Add emails to unsubscribe list -
lemn.lists.getContactData(email)
: Retrieve contact data -
lemn.lists.deleteContactData(email)
: Delete contact data -
lemn.lists.getAllTags()
: Get all tags
-
lemn.broadcasts.getUserRoutes()
: Get available postal routes -
lemn.broadcasts.uploadFile(file)
: Upload a file -
lemn.broadcasts.create(broadcastData)
: Create a new broadcast -
lemn.broadcasts.getAll(options)
: Get all broadcasts with optional filters -
lemn.broadcasts.get(id)
: Get a specific broadcast -
lemn.broadcasts.updateDraft(id, updateData)
: Update a draft broadcast -
lemn.broadcasts.delete(id)
: Delete a broadcast -
lemn.broadcasts.start(id)
: Start sending a broadcast -
lemn.broadcasts.sendTest(id, testData)
: Send a test email -
lemn.broadcasts.cancel(id)
: Cancel a broadcast -
lemn.broadcasts.duplicate(id)
: Duplicate a broadcast -
lemn.broadcasts.updateSent(id, updateData)
: Update a sent broadcast -
lemn.broadcasts.export(id)
: Export broadcast data -
lemn.broadcasts.getDomainStats(id)
: Get domain statistics for a broadcast -
lemn.broadcasts.getClientStats(id)
: Get client statistics -
lemn.broadcasts.getBounceMessages(id, domain, type)
: Get bounce messages
-
lemn.supplists.create(listName)
: Create a new suppression list -
lemn.supplists.getAll()
: Get all suppression lists -
lemn.supplists.get(listId)
: Get a specific suppression list -
lemn.supplists.update(listId, newName)
: Update a suppression list -
lemn.supplists.delete(listId)
: Delete a suppression list -
lemn.supplists.addData(listId, data)
: Add data to a suppression list
-
lemn.exclusion.getAll()
: Retrieve all exclusion lists -
lemn.exclusion.addToList(id, data)
: Add data to an exclusion list
-
lemn.exports.getAll()
: Retrieve all exported files
-
lemn.transactional.send(messageData)
: Send a transactional message
-
lemn.webhooks.createWebhook(data)
: Create a new webhook -
lemn.webhooks.getAllWebhooks()
: Retrieve all webhooks -
lemn.webhooks.updateWebhook(id, data)
: Update a webhook -
lemn.webhooks.deleteWebhook(id)
: Delete a webhook
const messageData = {
fromname: 'Your Company',
fromemail: 'noreply@yourcompany.com',
to: 'recipient@example.com',
toname: 'John Doe',
subject: 'Welcome to Our Service',
body: '<h1>Welcome!</h1><p>Thank you for signing up.</p>',
tag: 'welcome-email',
variables: {
username: 'johndoe'
}
};
lemn.transactional.send(messageData)
.then(result => console.log('Email sent:', result))
.catch(error => console.error('Email sending failed:', error));
All methods return Promises and can be caught for error handling:
lemn.lists.create('New List')
.then(result => console.log(result))
.catch(error => {
console.error('API Error:', error.message);
// Handle specific error scenarios
});
-
node-fetch
: For making HTTP requests -
form-data
: For handling multipart form data (file uploads)
This package requires Node.js version 16 or higher due to fetch and async/await usage.
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
MIT License
For support, please contact manojk030303@gmail.com (dev) , mail@normanszobotka.com (founder) or visit [lemon guides and usecases]
This is an unofficial Node.js client for the Lemn API. Always refer to the official Lemn documentation for the most up-to-date API specifications.