Basic MailerLite integration with Cloudflare Workers
For an extensive guide, please read my blog post
- Clone this repository with
git clone https://github.com/samjmck/cloudflare-workers-mailerlite.git cdinto the repository withcd cloudflare-workers-mailerlite- Deploy the Worker with
wrangler publish --name mailerlite - In the Cloudflare Workers dashboard, select the
mailerliteworker and a route to the worker, such as/newsletter - Add your MailerLite API token to the enviroment variables of your Cloudflare Worker under the name
MAILERLITE_API_TOKEN
This is some demo code for how a request should look like:
const response = await fetch("/newsletter", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email,
groups_ids: groupIds, // groupIds needs to be strings
}),
});The group IDs are the groups the subscriber will be added to. The ID of a group can be found by opening the groups section in the subscribers tab in the MailerLite dashboard, clicking on "View group" and then looking at the group query parameter in the URL.
See /template for some basic HTML, CSS and JS you can use to add a newsletter form to your website.