Skip to content

Mailchimp OAuth

JsWorkflows provides a platform-managed Mailchimp OAuth app — you do not need to create a Mailchimp app or provide credentials.

Mailchimp OAuth grants full account access — there are no granular scope selections. All connected resources (audiences, campaigns, automations) are available once you authorise.

  1. Go to OAuth Connections → Add Connection → Mailchimp.
  2. Click through to the Mailchimp authorisation screen.
  3. Log in and click Allow.
  4. Give the connection a handle (e.g., my-mailchimp).

Mailchimp tokens do not expire and are not automatically refreshed.

Mailchimp routes API requests through a data-centre-specific base URL (e.g., https://us1.api.mailchimp.com). After connecting, call the metadata endpoint to retrieve it:

const { token } = await api.getOAuthToken('my-mailchimp');
const meta = await (await fetch('https://login.mailchimp.com/oauth2/metadata', {
headers: { 'Authorization': `OAuth ${token}` },
})).json();
const apiBase = meta.api_endpoint; // e.g. "https://us1.api.mailchimp.com"

Example — add a subscriber to an audience

Section titled “Example — add a subscriber to an audience”
class Workflow {
async start(data, headers, api) {
const { token, error } = await api.getOAuthToken('my-mailchimp');
if (error) { api.log('OAuth error:', error); return; }
await api.scheduleNextStep({
delay: 10,
action: 'subscribe',
payload: {
token,
email: data.email,
firstName: data.customer?.first_name,
lastName: data.customer?.last_name,
},
});
}
async subscribe({ token, email, firstName, lastName }, headers, api) {
// Get the data centre from the metadata endpoint
const meta = await (await fetch('https://login.mailchimp.com/oauth2/metadata', {
headers: { 'Authorization': `OAuth ${token}` },
})).json();
const listId = env.MAILCHIMP_LIST_ID;
await fetch(`${meta.api_endpoint}/3.0/lists/${listId}/members`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify({
email_address: email,
status: 'subscribed',
merge_fields: { FNAME: firstName || '', LNAME: lastName || '' },
}),
});
}
}