1.0.0 • Published 6 months ago
lemn-api v1.0.0
Lemn API Node.js Client
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.
Installation
Install the package using npm:
npm install lemn-api
Quick Start
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);
}
}
API Reference
Initialization
const LemnAPI = require('lemn-api');
const lemn = new LemnAPI(apiKey, options);
Parameters
apiKey
(required): Your Lemn API keyoptions
(optional):baseUrl
: Custom base URL (defaults to Lemn's API endpoint)
Available Methods
Lists
lemn.lists.create(name)
: Create a new contact listlemn.lists.getAll()
: Retrieve all listslemn.lists.get(id)
: Get a specific list by IDlemn.lists.update(id, updatedData)
: Update a listlemn.lists.delete(id)
: Delete a listlemn.lists.export(id)
: Export a listlemn.lists.addData(id, csvData)
: Add data to a list via CSVlemn.lists.addSingleContact(listId, contact)
: Add a single contact to a listlemn.lists.getDomainStats(listId)
: Get domain statistics for a listlemn.lists.deleteDomains(listId, domains)
: Delete specific domains from a listlemn.lists.deleteContacts(listId, emails)
: Delete contacts from a listlemn.lists.addUnsubscribes(listId, emails)
: Add emails to unsubscribe listlemn.lists.getContactData(email)
: Retrieve contact datalemn.lists.deleteContactData(email)
: Delete contact datalemn.lists.getAllTags()
: Get all tags
Broadcasts
lemn.broadcasts.getUserRoutes()
: Get available postal routeslemn.broadcasts.uploadFile(file)
: Upload a filelemn.broadcasts.create(broadcastData)
: Create a new broadcastlemn.broadcasts.getAll(options)
: Get all broadcasts with optional filterslemn.broadcasts.get(id)
: Get a specific broadcastlemn.broadcasts.updateDraft(id, updateData)
: Update a draft broadcastlemn.broadcasts.delete(id)
: Delete a broadcastlemn.broadcasts.start(id)
: Start sending a broadcastlemn.broadcasts.sendTest(id, testData)
: Send a test emaillemn.broadcasts.cancel(id)
: Cancel a broadcastlemn.broadcasts.duplicate(id)
: Duplicate a broadcastlemn.broadcasts.updateSent(id, updateData)
: Update a sent broadcastlemn.broadcasts.export(id)
: Export broadcast datalemn.broadcasts.getDomainStats(id)
: Get domain statistics for a broadcastlemn.broadcasts.getClientStats(id)
: Get client statisticslemn.broadcasts.getBounceMessages(id, domain, type)
: Get bounce messages
Suppression Lists
lemn.supplists.create(listName)
: Create a new suppression listlemn.supplists.getAll()
: Get all suppression listslemn.supplists.get(listId)
: Get a specific suppression listlemn.supplists.update(listId, newName)
: Update a suppression listlemn.supplists.delete(listId)
: Delete a suppression listlemn.supplists.addData(listId, data)
: Add data to a suppression list
Exclusion Lists
lemn.exclusion.getAll()
: Retrieve all exclusion listslemn.exclusion.addToList(id, data)
: Add data to an exclusion list
Exports
lemn.exports.getAll()
: Retrieve all exported files
Transactional Emails
lemn.transactional.send(messageData)
: Send a transactional message
Webhooks
lemn.webhooks.createWebhook(data)
: Create a new webhooklemn.webhooks.getAllWebhooks()
: Retrieve all webhookslemn.webhooks.updateWebhook(id, data)
: Update a webhooklemn.webhooks.deleteWebhook(id)
: Delete a webhook
Sending a Transactional Email Example
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));
Error Handling
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
});
Dependencies
node-fetch
: For making HTTP requestsform-data
: For handling multipart form data (file uploads)
Minimum Node.js Version
This package requires Node.js version 16 or higher due to fetch and async/await usage.
Contributing
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
License
MIT License
Support
For support, please contact manojk030303@gmail.com (dev) , mail@normanszobotka.com (founder) or visit [lemon guides and usecases]
Disclaimer
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.
1.0.0
6 months ago