> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketflows.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send messages when something happens in your product

> Define an event, track it from your product, and let businesses automate messages from it

This guide takes one event, a customer booking an appointment, from your product
to a message sent by a business. For the model behind this, see
[How events and triggers work](https://docs.pocketflows.com/concepts/events-and-triggers.md).

## Prerequisites

* A business with customers. See
  [Sync businesses and customers](https://docs.pocketflows.com/how-to/sync-businesses-and-customers.md).
* Your `project_id` and `secret_key`. See
  [Authentication](https://docs.pocketflows.com/reference/authentication.md).

## 1. Define the event

Define the event once for your project. Give it a name and a phrase that
completes the sentence "When...", which is what businesses see when they choose
what a trigger listens for.

In the dashboard, open
[Resources > Triggering Events](https://dashboard.pocketflows.com/resources/project_defined_events)
and create a new event. Or use the API:

```
POST /project_defined_events

Body
{
  "event": "appointment.booked",
  "display_text": "a customer books an appointment"
}
```

The response includes the event's `id`, which starts with `pde_`.

## 2. Track the event

When the event happens in your product, send it for the business it happened in.
Set `event` to the event's `id` or its name, and identify the customer inside
`data`.

```
POST /businesses/:id/track

Body
{
  "event": "appointment.booked",
  "data": {
    "customer_external_id": "your_customer_id",
    "service": "Haircut",
    "starts_at": "2026-03-31T16:42:03Z"
  }
}
```

The response is the stored event, including its `id`. The request succeeds as
soon as the event is stored. Matching it to a customer and to triggers happens
afterwards.

You can identify the customer by your own identifier, as above, or by the
Pocketflows ID. See
[Tracking event payload examples](https://docs.pocketflows.com/reference/tracking-event-payloads.md#customer-identification).

Include any other details in `data` that a business might want to filter on or
mention in a message.

## 3. Set up a trigger for the business

A business sets up its own trigger in the embed:

1. [Create an embed](https://docs.pocketflows.com/how-to/render-an-embed.md) for the business and open
   **Triggers**.
2. Create a trigger and choose your event, shown as "When a customer books an
   appointment".
3. Add the messages to send and activate the trigger.

A trigger only runs while it is active.

To save each business from building the same trigger, give them a ready-made
one. See
[Give businesses pre-built campaigns, triggers and emails](https://docs.pocketflows.com/how-to/offer-prebuilt-templates.md).

## 4. Check that it worked

Track the event again for a customer of that business, then look up what it did:

```
GET /events/:id
```

`customer` is the ID of the customer the event was matched to. It is `null`
until the event has been processed, and stays `null` if no customer matched.

```
GET /events/:id/trigger_executions
```

This lists the trigger executions the event started, one per trigger that
matched.

## Troubleshooting

If the event started nothing, check these in order:

* **`customer` is `null` on the event.** The identifier in `data` does not match
  a customer of this business. Customers belong to one business, so check that
  you tracked the event for the business the customer was synced into.
* **The event name does not match.** The `event` you sent must be the `id` or
  the exact `event` name of a project-defined event in the same project. Test
  mode and live mode are separate projects, each with its own events.
* **No trigger is active.** The business has no active trigger listening for
  this event, or the trigger's filter excludes this customer or event.

## Related

* [How events and triggers work](https://docs.pocketflows.com/concepts/events-and-triggers.md) for what happens
  after an event is tracked.
* [Tracking event payload examples](https://docs.pocketflows.com/reference/tracking-event-payloads.md) for
  request bodies.
* [How personalization variables work](https://docs.pocketflows.com/concepts/personalization-variables.md) to
  use event data in a message.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.