# Start a workflow from Mailchimp events

> Run a workflow when someone subscribes to, unsubscribes from, or updates their profile in a Mailchimp audience, with a Webhook block.

To run a workflow when someone subscribes to a Mailchimp audience, unsubscribes from it, or changes their profile or email address, add a **Webhook** block whose **Source** is **Mailchimp** and give its URL to a webhook of the audience. Mailchimp posts one event per request. Each event starts its own run.

This source receives the audience webhooks of Mailchimp's marketing product. For the events of emails sent through Mailchimp Transactional, choose the **Mailchimp Transactional (Mandrill)** source instead.

You need a Mailchimp account in which you can change the audience's settings, and edit access to the workflow's project. The Mailchimp steps happen in Mailchimp's own console.

## Add the Webhook block and generate its URL

1. In a draft workflow, add a **Webhook** block. The block palette also lists **Mailchimp webhook** in the **Start** group, which adds the block with its source already set.
2. Under **Source**, choose **Mailchimp**. The line under the setting reads "Verifies the signature · one run per event · skips duplicates".
3. Under **Webhook URL**, select **Generate URL**, then copy the URL.

The badge beside the URL reads "Runs start after publish". The URL contains a token, and anyone who has the URL can send requests to it. Keep it out of shared documents.

## Create the webhook in Mailchimp with signing turned on

Mailchimp signs a webhook's requests only when signing is turned on for that webhook. It is off unless you turn it on. Mailchimp shows the signing secret once, right after you save the webhook, so have the block's settings open in OutWin before you start.

1. In Mailchimp, open **Audience** and choose the audience. Select **Manage Audience**, then **Settings**, then **Webhooks**.
2. Select **Create New Webhook**.
3. Paste the URL you copied into **Callback URL**.
4. Tick the kinds of update Mailchimp sends to this URL.
5. Turn on signing for the webhook.
6. Select **Save**. Mailchimp shows the signing secret. Copy it before you leave the page.

When the webhook is created, Mailchimp checks that the URL answers. The block answers the check itself, also while the workflow is a draft. **Recent deliveries** lists the check as **Handshake** with "Mailchimp checked that the URL answers.", and the last line under **Set up** reads the same. It starts no run.

The Webhook block offers these Mailchimp event types: `subscribe`, `unsubscribe`, `profile`, `upemail`, `cleaned`, and `campaign`.

## Save the Signing secret

1. In OutWin, paste the secret into **Signing secret** in the block's settings.
2. Select **Save**.

After you save, the settings show only the last four characters of the secret, with **Replace** and **Remove**. Under **Set up**, the second line changes to "The signing secret is saved: deliveries are verified."

Mailchimp cannot show the secret again. If you lose it before you save it, delete the webhook in Mailchimp, create a new one with signing turned on, and save the new secret.

Mailchimp issues the secret for one webhook, so OutWin saves it on the block's URL. It is not saved on a connection. A second Webhook block has its own URL and needs its own Mailchimp webhook and secret.

With a secret saved, OutWin also checks the time in the signature. A request signed more than five minutes before or after the moment it arrives is listed as **Refused**.

Without a saved secret the block still starts runs, and nothing is verified: anyone who has the URL can start the workflow. That is also the case for a webhook created without signing, which has no secret to save. Publishing then shows a warning that ends "has no signing secret saved, so its deliveries are not verified: anyone who has this URL can start this workflow". The warning does not block publishing.

## Choose which events start a run

Under **Events that start a run**, tick the event types that start a run. With none ticked, every event Mailchimp sends starts a run. To start runs for a type that is not listed, type it into the box under the list and select **Add**.

An event whose type is not ticked is listed as **Filtered out** and starts no run. To narrow further by a field of the event, add a row under **Only when**. Mailchimp puts the subscriber's details under `data`, so a field of them has a path that starts with `body.data`, such as `body.data.email`. [Webhook settings](https://outwin.ai/docs/reference/triggers-approvals-and-waits/#webhook-settings) lists the comparisons.

## Send a test and check what arrived

1. In Mailchimp, cause one of the updates the webhook sends, for example by subscribing a test address through the audience's sign-up form.
2. In OutWin, look under **Recent deliveries** in the block's settings.

**Recent deliveries** lists every event that reached the URL, including while the workflow is a draft. On a draft each event is listed as **Dropped** with "The workflow is not published, so nothing ran." It starts no run and is not run later. The last line under **Set up** changes from "Mailchimp checked that the URL answers." to, for example, "Received subscribe. Dropped."

With a secret saved, an event listed as **Dropped** on a draft has passed the signature check. A delivery that fails the check is listed as **Refused**.

If you have edit access, select an event to see what the block passed on. The list is kept for seven days, and the data of the newest 20 events is kept.

## Read the event in the next block

Each run receives one Mailchimp event. Mailchimp sends it as a form, and the block passes the form's fields on as the body, with the subscriber's details grouped under `data`. An HTTP request block or a database block directly after the Webhook block reads it with these expressions. An AI block such as **Think** receives the whole value as its input.

| Expression | What it holds |
| --- | --- |
| `{{input.body}}` | The event as Mailchimp sent it, with the fields `type`, `fired_at`, and `data`. |
| `{{input.body.data}}` | The details of the subscriber the event is about, with fields such as `id`, `list_id`, and `email`. Other fields depend on the event type. |
| `{{input.body.data.email}}` | One field of those details. Read any other field the same way. |
| `{{input.event.type}}` | The event's type, such as `subscribe`. It is the event's `type` field. |
| `{{input.event.id}}` | An id OutWin builds from the event's `type`, `fired_at`, `data.id`, and `data.email` fields, because Mailchimp sends no id for an event. |
| `{{input.event.time}}` | The event's time as an ISO 8601 date and time. `{{input.body.fired_at}}` holds the same moment as Mailchimp sent it. |
| `{{input.delivery.verified}}` | `true` only when the signature was checked and passed. |

A block further along reads the same values through the Webhook block's name, as in `{{steps["Mailchimp"].body.data.email}}` for a block named `Mailchimp`. [Data and context](https://outwin.ai/docs/reference/data-and-context/) describes what each block passes on.

## Publish and check the runs

[Publish the workflow](https://outwin.ai/docs/run/publish-and-start/). From then on, each event that passes the filter starts a run. On a published workflow the block's settings are read-only, and **Recent deliveries** is in the block's inspector. You can still replace the secret there.

| Outcome | What happened |
| --- | --- |
| **Ran** | The event started a run. |
| **Waiting** | 10 runs of the workflow are already active. The event starts a run when one of them ends. An event that waits longer than an hour is listed as **Dropped**. |
| **Duplicate** | An event of the same type, fired in the same second for the same subscriber, already ran in the last 72 hours. The line reads "This event was already received and run, so it did not run again." |
| **Handshake** | Mailchimp's check of the URL. It starts no run. |

Runs start in the order events arrive. That is not always the order things happened, so do not build a workflow that relies on `subscribe` arriving before `profile`.

Receiving an event costs no credits, and neither does an event that is filtered out, a duplicate, or a handshake. A run that starts uses credits for the blocks that run in it.

## If nothing runs

Open **Recent deliveries** and read the outcome and the sentence beside the newest event.

| What you see | Cause | Fix |
| --- | --- | --- |
| "Nothing has arrived yet." | No request has reached the URL, not even the check of the URL. | Check that **Callback URL** on the webhook in Mailchimp is the block's current URL. **Rotate token** on a published workflow changes the URL, and the old one stops working. |
| **Handshake** and nothing else | Mailchimp reached the URL, and no update the webhook sends has happened since. | Check that the webhook is on the audience you changed and that it sends the kind of update you caused, and cause it again. |
| **Dropped** with "The workflow is not published, so nothing ran." | The workflow is a draft. | Publish the workflow. Events that arrived before then are not run later. |
| **Dropped** with "The workflow is paused, so nothing ran." | The workflow is paused. | Resume the workflow. Events that arrived while it was paused are not run later. |
| **Filtered out** with `Events of type "profile" are not chosen on this trigger.` | The event's type is not ticked under **Events that start a run**. | Tick the type, or clear every tick so that all events start a run. The settings are read-only on a published workflow. |
| **Refused** with "The signature did not match. Check that the secret saved here is the one the sender shows for this URL." | The saved secret is not the one Mailchimp showed for this webhook, for example because it was copied from another webhook. | Mailchimp cannot show the secret again. Delete the webhook in Mailchimp, create a new one with signing turned on, copy its secret, and select **Replace**. You do not republish the workflow. |
| **Refused** with "The request carried no signature." | A secret is saved in OutWin, and the request did not carry Mailchimp's signature. Signing is not turned on for the webhook, or the request was sent by hand to try the URL. | Create a webhook in Mailchimp with signing turned on, save the secret it shows with **Replace**, and delete the old webhook. To receive the events unverified, select **Remove** in OutWin. |
| **Refused** with "The request's timestamp is too far from now, so it may be a replay of an old delivery." | The request was signed more than five minutes before or after it arrived, for example because a saved copy of an earlier request was sent again. | Cause a new event in Mailchimp. |

A delivery listed as **Refused** is answered with status `401` and starts nothing. OutWin keeps none of its data. For every other outcome in the table, Mailchimp receives a success response and OutWin does not run the event later.
