# Send an Event

> Send an event from your own system to record what a person did and start journeys for them

URL: https://docs.lemuai.com/api-reference/events/trigger

Sends an event that happened in your own system, such as an abandoned cart, a placed order or a submitted form. LemuAI stores it, links it to the right contact, and starts every active journey whose [API Events trigger](https://docs.lemuai.com/automation/nodes-and-triggers) listens for the same `event_type`.

Use this to start a journey, for example a WhatsApp message or a follow-up call an hour after a cart is abandoned. To call one number straight away with a voice agent, use [Trigger an outbound call](https://docs.lemuai.com/api-reference/calls/trigger) instead.

**Endpoint:** `POST /api/v1/events`

## Headers

| Name | Required | Description |
|---|---|---|
| `X-API-Key` | Yes | An API key from your organization. See [Authentication](https://docs.lemuai.com/api-reference/authentication). |
| `Content-Type` | Yes | `application/json` |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `event_type` | string | Yes | The name of the event, 1 to 100 characters, for example `Purchase`, `InitiateCheckout` or your own `cart_abandoned`. Journeys whose API Events trigger uses the same `event_type` start for this contact. See [Event names](#event-names). |
| `phone` | string | No | The person's phone number in international format, for example `+919876543210`, up to 50 characters. |
| `email` | string | No | The person's email address, up to 254 characters. |
| `external_id` | string | No | Your own id for the person, for example a CRM or customer id, up to 255 characters. |
| `anonymous_id` | string | No | The visitor id set by the LemuAI website snippet or an app SDK (see [Tracking Sources](https://docs.lemuai.com/website-pixel/overview)), up to 512 characters. Send it to tie website or app activity to the person once they sign up or check out. |
| `list_name` | string | No | A contact list name, up to 255 characters. The contact is added to this list, and the list is created if it doesn't exist yet. |
| `data` | object | No | Any details about the event, such as order id, amount or product. Journeys started by this event can use these values (see below). For a `Purchase`, include `value`, `currency` and `order_id` (see [Orders and revenue](#orders-and-revenue)). |

Send at least one of `phone`, `email`, `external_id` or `anonymous_id` to link the event to a person. An event with none of them is stored but not linked to a contact.

If `data` contains `first_name` and `last_name` (or `name`, `full_name`, `contact_name` or `customer_name`), the name is saved on the contact.

## Event names

Use Meta's standard event names where one fits, such as `Purchase`, `AddToCart`, `InitiateCheckout` or `Lead`. They are matched whatever the case or separators: `purchase`, `PURCHASE` and `Purchase` are all stored as `Purchase`, and `add_to_cart` as `AddToCart`. Any other name is a custom event and is stored as you sent it.

Older names such as `order_placed` and `cart_added` still match `Purchase` and `InitiateCheckout` in journeys and segments. See [Standard and conversion events](https://docs.lemuai.com/website-pixel/standard-events) for the full list.

## Orders and revenue

A `Purchase` (or any other event listed under **Conversion events** in [Sending Limits](https://docs.lemuai.com/settings/sending-limits#conversion-events)) counts as an order for journey and campaign revenue and ROI. Include these fields in `data`:

| Field | Type | Description |
|---|---|---|
| `value` | number | The order total in major units, for example `1499.5` |
| `currency` | string | An ISO 4217 code, for example `INR` |
| `order_id` | string | Your id for the order. The same order reported more than once, by this API, your website, your app or Shopify, counts once |

The event is never rejected for a missing field. An order without a value counts with no revenue, a missing currency is replaced by your workspace currency, and an order without an `order_id` counts every time it is sent.

**cURL**

```bash
curl -X POST https://app.lemuai.com/api/v1/events \
  -H "X-API-Key: lemu_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "event_type": "Purchase",
    "phone": "+919876543210",
    "data": {
      "value": 1499.5,
      "currency": "INR",
      "order_id": "1042",
      "content_ids": ["SKU1"]
    }
  }'
```

**JavaScript**

```js
const res = await fetch("https://app.lemuai.com/api/v1/events", {
  method: "POST",
  headers: {
    "X-API-Key": process.env.LEMU_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "event_type": "Purchase",
    "phone": "+919876543210",
    "data": {
      "value": 1499.5,
      "currency": "INR",
      "order_id": "1042",
      "content_ids": [
        "SKU1"
      ]
    }
  }),
});
if (!res.ok) throw new Error(`LemuAI API ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(data);
```

**Python**

```python
import os

import requests

response = requests.post(
    "https://app.lemuai.com/api/v1/events",
    headers={
        "X-API-Key": os.environ["LEMU_API_KEY"],
    },
    json={
        "event_type": "Purchase",
        "phone": "+919876543210",
        "data": {
            "value": 1499.5,
            "currency": "INR",
            "order_id": "1042",
            "content_ids": [
                "SKU1",
            ],
        },
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

## How the contact is found

LemuAI looks up every identifier you send (`phone`, `email`, `external_id` and `anonymous_id`) and works out which person they belong to:

1. **One match.** If the identifiers point to one existing contact, the event is linked to it, and any new identifiers you sent are added to that contact.
2. **Several matches.** If they point to two or more contacts that are clearly the same person (for example the phone matches one contact and the email matches another, and nothing conflicts), those contacts are merged into one and the event is linked to it. Contacts are not merged when that would join two different people, for example two contacts that each have a different email. In that case the event is linked to the main matching contact and nothing is merged.
3. **No match.** A new contact is created, but only when you sent a `phone` or an `email`. An `external_id` or `anonymous_id` on its own links to an existing contact or to none; it never creates one.

A website visitor id that was linked to another person before moves to the person in this event.

**Example request:**

**cURL**

```bash
curl -X POST https://app.lemuai.com/api/v1/events \
  -H "X-API-Key: lemu_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "event_type": "cart_abandoned",
    "phone": "+919876543210",
    "email": "priya@example.com",
    "external_id": "cust-58214",
    "list_name": "Abandoned carts",
    "data": {
      "first_name": "Priya",
      "cart_amount": 2499,
      "product_name": "Running shoes"
    }
  }'
```

**JavaScript**

```js
const res = await fetch("https://app.lemuai.com/api/v1/events", {
  method: "POST",
  headers: {
    "X-API-Key": process.env.LEMU_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "event_type": "cart_abandoned",
    "phone": "+919876543210",
    "email": "priya@example.com",
    "external_id": "cust-58214",
    "list_name": "Abandoned carts",
    "data": {
      "first_name": "Priya",
      "cart_amount": 2499,
      "product_name": "Running shoes"
    }
  }),
});
if (!res.ok) throw new Error(`LemuAI API ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(data);
```

**Python**

```python
import os

import requests

response = requests.post(
    "https://app.lemuai.com/api/v1/events",
    headers={
        "X-API-Key": os.environ["LEMU_API_KEY"],
    },
    json={
        "event_type": "cart_abandoned",
        "phone": "+919876543210",
        "email": "priya@example.com",
        "external_id": "cust-58214",
        "list_name": "Abandoned carts",
        "data": {
            "first_name": "Priya",
            "cart_amount": 2499,
            "product_name": "Running shoes",
        },
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

## Response

**`201`**: the event was stored and matching journeys were queued.
```json
{
  "event_id": 90412,
  "contact_id": 5531,
  "triggered_workflows": 0
}
```

| Field | Type | Description |
|---|---|---|
| `event_id` | integer | The id of the stored event. It appears in the [Event Log](https://docs.lemuai.com/event-log/overview). |
| `contact_id` | integer or null | The contact the event was linked to. `null` when no identifier was sent, when only an `external_id` or `anonymous_id` was sent and no contact has it, or when your plan's contact limit stopped a new contact being created. |
| `triggered_workflows` | integer | Always `0`. Journeys are started in the background just after the response, so the count isn't known yet. Check the Event Log or the journey's runs to see what ran. |

## Using event data in a journey

A journey started by this event gets `phone`, `event_type` and `event_id`, plus every field from `data` (or only the fields picked in the trigger's context mapping). With the request above, a call step in the journey can use `{{first_name}}`, `{{cart_amount}}` and `{{product_name}}` in the agent's prompt.

On the journey's API Events trigger you can also:

- wait before running, for example 60 minutes after `cart_abandoned`;
- cancel the run if another event arrives for the same contact first, for example `Purchase`;
- only run for contacts in a chosen list.

See [Journey nodes and triggers](https://docs.lemuai.com/automation/nodes-and-triggers) for the full trigger settings.

**Note:** A new contact created from an event is tagged `event` and counts toward your plan's contact limit. If you've reached the limit, the event is still stored, but no contact is created and `contact_id` is `null`.

## Errors

| Status | When |
|---|---|
| `401` | The API key is missing or not valid. |
| `422` | `event_type` is missing or too long, or another field is too long or has the wrong type. |

See [Errors](https://docs.lemuai.com/api-reference/errors) for the error format.
