Last active
December 14, 2023 12:42
-
-
Save cloudhooks/a777b226cc08f3c43729d267765e432f to your computer and use it in GitHub Desktop.
Adds the customer's email address to MailerLite via the MailerLite API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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