# Webhooks

> Receive a JSON POST each time something happens in your Emelia campaigns: email sent, opened, clicked, replied, bounced, LinkedIn invitation accepted, WhatsApp reply, campaign finished.

Source: https://docs.emelia.io/docs/webhooks

A webhook is a URL that Emelia calls with a JSON `POST` each time a selected event happens in a campaign: a reply, an acceptance, a bounce. Use it to update your CRM, alert your team or route replies the moment they arrive.

The routes below work on advanced campaigns, the multichannel campaigns of the current app.

## Create a webhook

[`POST /webhook`](https://docs.emelia.io/docs/webhooks/create-webhook.md)

**curl**

```bash
curl -X POST https://api.emelia.io/webhook \
  -H "Authorization: $EMELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "hookUrl": "https://hooks.yourcompany.com/emelia/9f2c4e1a7b",
    "campaignId": "6651f0c2a1b2c3d4e5f60718",
    "type": "advanced",
    "events": ["MAIL_REPLIED", "LINKEDIN_REPLIED"]
  }'
```

**JavaScript**

```js
const res = await fetch('https://api.emelia.io/webhook', {
  method: 'POST',
  headers: {
    Authorization: process.env.EMELIA_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    hookUrl: 'https://hooks.yourcompany.com/emelia/9f2c4e1a7b',
    campaignId: '6651f0c2a1b2c3d4e5f60718',
    type: 'advanced',
    events: ['MAIL_REPLIED', 'LINKEDIN_REPLIED'],
  }),
});
const { webhookId } = await res.json();
```

**Python**

```python
import os
import requests

res = requests.post(
    "https://api.emelia.io/webhook",
    headers={"Authorization": os.environ["EMELIA_API_KEY"]},
    json={
        "hookUrl": "https://hooks.yourcompany.com/emelia/9f2c4e1a7b",
        "campaignId": "6651f0c2a1b2c3d4e5f60718",
        "type": "advanced",
        "events": ["MAIL_REPLIED", "LINKEDIN_REPLIED"],
    },
)
webhook_id = res.json()["webhookId"]
```

```json title="Response"
{ "success": true, "webhookId": "6702c1d4e5f6a7b8c9d0e1f2" }
```

| Field        | Value                                                                                                                      |
| ------------ | -------------------------------------------------------------------------------------------------------------------------- |
| `hookUrl`    | The URL that receives the events. Use a public HTTPS URL that is hard to guess.                                            |
| `campaignId` | The id of a campaign, or `ALL_CAMPAIGNS` for all your campaigns, current and future, except the finished or archived ones. |
| `type`       | Always `advanced`. Without it, the route works on legacy campaigns.                                                        |
| `events`     | The [events](#events) to receive. A misspelled name is accepted and never fires.                                           |

To change the events of a URL on a campaign, delete the URL and create it again: a URL registered twice receives everything twice.

With `ALL_CAMPAIGNS`, `webhookId` is the id of your account. Read the ids of the registrations with [List webhooks](#list-and-delete-your-webhooks).

## Send a test event

[`POST /webhook/{hookId}/test`](https://docs.emelia.io/docs/webhooks/send-test-event.md)

**curl**

```bash
curl -X POST https://api.emelia.io/webhook/6702c1d4e5f6a7b8c9d0e1f2/test \
  -H "Authorization: $EMELIA_API_KEY"
```

**JavaScript**

```js
await fetch(`https://api.emelia.io/webhook/${webhookId}/test`, {
  method: 'POST',
  headers: { Authorization: process.env.EMELIA_API_KEY },
});
```

**Python**

```python
requests.post(
    f"https://api.emelia.io/webhook/{webhook_id}/test",
    headers={"Authorization": os.environ["EMELIA_API_KEY"]},
)
```

Your URL receives a `MAIL_REPLIED` event with `test: true` and a fake contact. A `success: true` response means that the event was sent, not that your endpoint accepted it: check on your side that it arrived.

## Events

Pick the names to pass in `events`. The full payload of each is on [Campaign activity](https://docs.emelia.io/docs/webhooks/campaign-activity.md) and [Campaign finished](https://docs.emelia.io/docs/webhooks/campaign-finished.md).

### Email

| Event               | When                                                                                                                                                                                                                                                                                        |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `EMAIL_SENT`        | An email step was sent. The name is `EMAIL_SENT`, not `MAIL_SENT`.                                                                                                                                                                                                                          |
| `OPENED`, `CLICKED` | The tracking pixel loaded, or a tracked link was clicked. Needs tracking on the campaign. Delivered 30 to 60 seconds later.                                                                                                                                                                 |
| `WEBSITE_VISITED`   | A contact who clicked a tracked link triggered one of your pixel rules that has the "Create an activity in the campaign" action, once per rule and per contact. Needs the Emelia pixel on the site. `rule` is the name of the rule, `link` the page seen. Delivered 30 to 60 seconds later. |
| `MAIL_REPLIED`      | First email reply of the contact, with `reply`, `sentiment`, `sender` and `messageId`.                                                                                                                                                                                                      |
| `RE_REPLY_EMAIL`    | Every later email of a contact who already replied, with `reply`, `date` (of the message) and `messageId`. No `sentiment`.                                                                                                                                                                  |
| `BOUNCED`           | A bounce was detected. No `campaign` field, `step` is 0.                                                                                                                                                                                                                                    |
| `UNSUBSCRIBED`      | The contact unsubscribed.                                                                                                                                                                                                                                                                   |

### LinkedIn

| Event                                                    | When                                                                                                                                  |
| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `VISITED`, `INVITED`, `ACCEPTED`, `INMAIL_SENT`, `LIKED` | LinkedIn actions.                                                                                                                     |
| `MESSAGE_SENT`                                           | A LinkedIn message was sent, with the text in `content`.                                                                              |
| `LINKEDIN_REPLIED`                                       | First LinkedIn reply of the contact, with `reply` and `sentiment`.                                                                    |
| `RE_REPLY_LINKEDIN`                                      | Every later LinkedIn message of a contact who already replied, with `reply`, `date` (of the message) and `messageId`. No `sentiment`. |

`RE_REPLY_EMAIL` and `RE_REPLY_LINKEDIN` are sent only if you subscribe to them. They are not stored: absent from the activities route, no replay, and nothing once the campaign is finished.

### WhatsApp

| Event                   | When                                         |
| ----------------------- | -------------------------------------------- |
| `WHATSAPP_MESSAGE_SENT` | A WhatsApp message was sent.                 |
| `WHATSAPP_REPLIED`      | A WhatsApp reply was received, with `reply`. |

### Campaign

| Event             | When                                                                                                 |
| ----------------- | ---------------------------------------------------------------------------------------------------- |
| `CAMPAIGN_ENDING` | The campaign was closed by the daily job, see [Campaign finished](https://docs.emelia.io/docs/webhooks/campaign-finished.md). |

Never sent for these campaigns: `SENT`, `MAIL_SENT`, `FOLLOWED`, `TASK_COMPLETED`, `TASK_FAILED`.

A `MAIL_REPLIED` delivery looks like this:

```json
{
  "event": "MAIL_REPLIED",
  "campaign": "Q4 SaaS founders",
  "campaignId": "6651f0c2a1b2c3d4e5f60718",
  "senderName": "Marie Martin",
  "sender": "marie.martin@yourcompany.com",
  "contact": {
    "id": "6703d2e5f6a7b8c9d0e1f2a3",
    "firstName": "Claire",
    "lastName": "Fontaine",
    "email": "claire.fontaine@nexora.io",
    "company": "Nexora"
  },
  "date": "2026-10-13T10:20:00.000Z",
  "step": 0,
  "reply": "Hi Marie, sounds interesting. Can we talk on Tuesday?",
  "sentiment": { "classification": "INTERESTED", "score": 0.92 },
  "messageId": "<CAF7x2y3z@mail.nexora.io>"
}
```

* `contact` starts with the custom variables of the contact, then the standard fields. `company` is the first custom variable whose name contains "company".
* `sentiment` is the AI classification of the reply: `INTERESTED`, `NOT_INTERESTED`, `NEUTRAL`, `OUT_OF_OFFICE`, `HOSTILE`, `DELEGATION`, `INCOMPREHENSION` or `QUESTION_ASK`, with a `score`. It is present only when reply classification runs on your account.
* `date` is an ISO 8601 date in UTC, usually the time Emelia processed the event.
* Absent fields are omitted, never `null`.

## Receive the events

Answer fast with a `2xx`, then do the work in the background.

**curl**

```bash
# Simulate a delivery on your local endpoint
curl -X POST https://hooks.yourcompany.com/emelia \
  -H "Content-Type: application/json" \
  -d '{"event": "MAIL_REPLIED", "campaign": "Q4 SaaS founders", "contact": {"email": "claire.fontaine@nexora.io"}, "date": "2026-10-13T10:20:00.000Z", "step": 0, "reply": "Can we talk on Tuesday?"}'
```

**JavaScript**

```js
import express from 'express';

const app = express();
app.use(express.json());

// Keep the path hard to guess: deliveries are not signed.
app.post('/emelia/9f2c4e1a7b', (req, res) => {
  res.sendStatus(200); // answer first
  const { event, contact, reply, sentiment } = req.body;
  if (event === 'MAIL_REPLIED' || event === 'LINKEDIN_REPLIED') {
    console.log(`${contact.email ?? contact.linkedinUrlProfile} replied (${sentiment?.classification}): ${reply}`);
  }
});

app.listen(3000);
```

**Python**

```python
from flask import Flask, request

app = Flask(__name__)

# Keep the path hard to guess: deliveries are not signed.
@app.post("/emelia/9f2c4e1a7b")
def emelia_webhook():
    payload = request.get_json(force=True)
    if payload.get("event") in ("MAIL_REPLIED", "LINKEDIN_REPLIED"):
        contact = payload.get("contact", {})
        print(contact.get("email"), "replied:", payload.get("reply"))
    return "", 200
```

## List and delete your webhooks

[`GET /webhook`](https://docs.emelia.io/docs/webhooks/list-webhooks.md)

```bash
curl https://api.emelia.io/webhook \
  -H "Authorization: $EMELIA_API_KEY"
```

```json title="Response"
{
  "webhooks": [
    {
      "id": "6702c1d4e5f6a7b8c9d0e1f2",
      "typeOfCampaign": "advanced",
      "campaignId": "6651f0c2a1b2c3d4e5f60718",
      "campaignName": "Q4 SaaS founders",
      "url": "https://hooks.yourcompany.com/emelia/9f2c4e1a7b",
      "events": ["MAIL_REPLIED", "LINKEDIN_REPLIED"],
      "status": "active"
    }
  ]
}
```

There is one entry per campaign: a URL registered on all your campaigns appears once for each of them.

[`DELETE /webhook`](https://docs.emelia.io/docs/webhooks/delete-webhook.md)

```bash
curl -X DELETE https://api.emelia.io/webhook \
  -H "Authorization: $EMELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "hookUrl": "https://hooks.yourcompany.com/emelia/9f2c4e1a7b",
    "campaignId": "6651f0c2a1b2c3d4e5f60718",
    "type": "advanced"
  }'
```

With `ALL_CAMPAIGNS` in `campaignId`, the URL is removed from all your campaigns and is no longer added to new ones.

You can also list, test and delete your webhooks in the Emelia app, in **Settings, API & Webhooks**.

## Delivery rules

Build your handler for these rules:

* **No signature.** Deliveries carry `Content-Type: application/json` and nothing else: no secret, no signature header. Use a URL that is hard to guess, and treat the payload as a hint: confirm important facts with the API before acting on them.
* **No retry on HTTP errors.** Your response is ignored. A few events are retried on network errors only. An endpoint that is down misses the events.
* **No ordering.** Events come from different services: an `OPENED` can arrive after the `MAIL_REPLIED`.
* **No event id.** To deduplicate, build a key from `event`, `campaign`, the contact and `step`. A URL registered twice on a campaign receives everything twice.
* **No timeout on Emelia's side**, but answer in a few seconds anyway.

Other webhooks: [legacy campaigns](https://docs.emelia.io/docs/campaigns/legacy.md) have their own events ([email](https://docs.emelia.io/docs/webhooks/legacy-email-activity.md), [LinkedIn](https://docs.emelia.io/docs/webhooks/legacy-linkedin-activity.md)), and the [LinkedIn scraper](https://docs.emelia.io/docs/linkedin-scraper.md) has its own `FINISHED` and `ERROR` webhooks.
