@emdash.email/sdk
v0.7.1
Published
A JavaScript SDK for interacting with the [Emdash](https://emdash.email) API.
Readme
@emdash.email/sdk
A JavaScript SDK for interacting with the Emdash API.
Installation
To install via NPM, run the following command from your project root:
npm i @emdash.email/sdkUsage
Initialization
To use the SDK, initialize it with your API key:
import Emdash from '@emdash.email/sdk';
const emdash = new Emdash({ api_key: 'your_api_key' });Sending Transactional Campaigns
To send a transactional campaign, use the emdash.campaigns.transactional.send method:
import Emdash from '@emdash.email/sdk';
const emdash = new Emdash({ api_key: 'your_api_key' });
const response = await emdash.campaigns.transactional.send('campaign_tag', {
to: '[email protected]',
variables: { example_variable: 'value' }
});Subscribing Users
To subscribe a user, use the emdash.lists.subscribe method:
import Emdash from '@emdash.email/sdk';
const emdash = new Emdash({ api_key: 'your_api_key' });
// NOTE: Grab list_id from the URL bar when looking at a list in Emdash.
const response = await emdash.lists.subscribe('list_id', {
email_address: '[email protected]',
first_name: 'First',
last_name: 'Last'
});Testing
To run the tests for this project, use the following command:
npm testThe tests cover various scenarios, including sending campaigns, subscribing users, handling network errors, and using custom API URLs.
