Skip to content

Instantly share code, notes, and snippets.

@cloudhooks
Last active December 14, 2023 12:42
Show Gist options
  • Save cloudhooks/a777b226cc08f3c43729d267765e432f to your computer and use it in GitHub Desktop.
Save cloudhooks/a777b226cc08f3c43729d267765e432f to your computer and use it in GitHub Desktop.
Adds the customer's email address to MailerLite via the MailerLite API.
const apiKey = 'Your Mailerlite API key';
const subscriberGroups = ['Subscriber group id1', 'Subscriber group id2'];
module.exports = async function(payload, actions) {
const httpConfig = {
headers: {
'Authorization': `Bearer ${apiKey}`
}
};
const subscriberParams = {
email: payload.customer.email,
fields: {
name: `${payload.customer.first_name} ${payload.customer.last_name}`
},
groups: subscriberGroups,
status: 'active'
};
try {
const {data: result} = await actions.http.post(
'https://connect.mailerlite.com/api/subscribers',
subscriberParams,
httpConfig
);
console.log('Subscription result: ', result);
} catch (err) {
console.log('Subscription error: ' + err);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment