Skip to content

Repository files navigation

wr-brevo-integration

A Cloudflare Worker that keeps Webround newsletter subscribers in sync with a Brevo contact list, bidirectionally.

How it works

Webround → Brevo: when a customer subscribes or unsubscribes on the storefront, Webround fires a webhook to this Worker, which adds or removes them from the configured Brevo list.

Brevo → Webround: when a contact unsubscribes from a Brevo email or is deleted, Brevo fires a webhook to this Worker, which sets newsletter=false on the matching Webround customer.

One-time bulk import (optional)

If needed, before enabling the real-time sync, run the bulk import script to align the existing Webround subscribers with your Brevo list:

# fill in your values in .env
npx ts-node scripts/bulk-import.ts

The script fetches all newsletter subscribers from Webround page by page and pushes them to Brevo in batches of 150. Running it multiple times is safe: updateExistingContacts=true prevents duplicates.

Setup

1. Configure vars

In wrangler.jsonc, set:

{
    "WR_API_URL": "https://commerce-api.webround.com/",
    "WR_STORE_ID": "your-store-id",
    "WR_USER_ID": "your-user-id",
    "BREVO_LIST_ID": "your-list-id"
}

2. Set secrets

Create a secrets.json file (never commit this):

{
    "WR_API_KEY": "your-wr-api-key",
    "BREVO_API_KEY": "your-brevo-api-key",
    "BREVO_WEBHOOK_SECRET": "your-brevo-webhook-secret",
    "WR_WEBHOOK_SECRET": "your-wr-webhook-secret"
}

Or set them one by one via the Wrangler CLI:

wrangler secret put WR_API_KEY
wrangler secret put BREVO_API_KEY
wrangler secret put BREVO_WEBHOOK_SECRET
wrangler secret put WR_WEBHOOK_SECRET

3. Deploy

make deploy

4. Configure webhooks

Webround: add a webhook pointing to https://your-worker.workers.dev/webhook/wr and subscribe to store.customer.newsletter.subscribed and store.customer.newsletter.unsubscribed.

Brevo: add a webhook pointing to https://your-worker.workers.dev/webhook/brevo, subscribe to unsubscribe and contactDeleted, and set the x-brevo-secret header to the value you used for BREVO_WEBHOOK_SECRET.

Environment variables

Variable Type Description
WR_API_URL var Webround API base URL
WR_STORE_ID var Webround store ID
WR_USER_ID var Webround admin user ID
BREVO_LIST_ID var Brevo list ID to sync
WR_API_KEY secret Webround API key
BREVO_API_KEY secret Brevo API key
BREVO_WEBHOOK_SECRET secret Shared secret for Brevo webhook validation
WR_WEBHOOK_SECRET secret Shared secret for Webround webhook validation

Built with

Releases

Packages

Contributors

Languages