# Flow triggers

Source: https://docs.revoplyai.com/flow-triggers/

> Start a WhatsApp flow for a customer when something happens in your system, by posting JSON to the flow's private URL.

A flow whose trigger is **Your system sends an event** gets a private URL. When your
system posts JSON to it (an order shipped, a form filled in, a payment failed), the flow
starts for the customer the JSON names, on your WhatsApp Business number.

```http
POST https://api.revoplyai.com/hooks/rvh_EXAMPLE…
Content-Type: application/json
Idempotency-Key: order-10482-shipped
```

Flow triggers are part of the Business plan. Only an Owner or an Admin can set them up.

## Rules [#rules]

* **WhatsApp Business numbers only.** The flow sends from a `whatsapp` channel: a number
  connected through Meta. A WhatsApp QR number cannot be used.
* **The flow must start with a template.** The customer has not written, so no service
  window is open; the flow cannot be published until it sends a template before anything
  else. See [WhatsApp messaging rules](/get-started/whatsapp-messaging-rules/).
* **The URL is the credential.** There is no API key: anyone who has the URL can start the
  flow. Call it from your server only, never from a browser or an app.
* An account can have up to 20 flow trigger URLs.

## Set one up [#set-one-up]

1. In **Automations**, create a flow and choose the trigger **Your system sends an event**.
2. Choose the **WhatsApp number** the flow messages customers from.
3. **Create the URL** and copy it. It is shown in full only once; afterwards the builder
   shows only its start.
4. Say where the customer's **phone number** is in your JSON, such as `customer.phone`.
   Optionally, say where their name and language are, and which values to keep as
   variables for the flow's steps. Send one request first and the builder offers its
   fields to tap. See [Sending requests](/flow-triggers/sending-requests/).
5. Build the flow, starting with a template step, then publish it and switch it on.

## What happens when a request is accepted [#what-happens-when-a-request-is-accepted]

1. We find the contact with that number, or create one (a new contact is tagged
   `webhook`), and the WhatsApp conversation with them on the flow's number, or create it.
2. A run of the flow is queued, and you get `202` with `"status": "accepted"` and the run's
   `id` at once. The run has not sent anything yet.
3. When the run ends, [`flow.completed`](/webhooks/events/flow-completed/) or
   [`flow.failed`](/webhooks/events/flow-failed/) carries the same run `id`, if an endpoint
   subscribes to them.

When the customer answers, their reply lands in the conversation the flow is waiting in.

Every other answer is explained in [Responses and errors](/flow-triggers/responses-and-errors/).

## Replace the URL [#replace-the-url]

**Replace the URL** in the trigger makes a new URL and shows it once. The old URL stops
working at once and answers `404 not_found`; update every system that sends to it.
Replace it whenever it may have leaked. [Idempotency keys](/get-started/idempotency/)
already used on the flow stay used.

## When requests are refused on our side [#when-requests-are-refused-on-our-side]

If flow triggers are paused on our side, or we cannot count requests, every request is
answered `503 service_unavailable`. Retry later with the same `Idempotency-Key`.
