# Build your first waterfall (routing)

> Add two destinations, set what a sale looks like, and test a lead.
> Source: https://www.eventsiq.io/docs/guide-first-waterfall


A waterfall offers a lead to your destinations one at a time, in the order you choose. The first
one whose reply counts as a sale takes it, and nobody below it is called.

This guide adds two destinations for a roofing offer, sets what a sale looks like, puts them in
order and tests a lead. You are finished when a test lead is sold to the first destination in the
order, and you have seen a lead pass down to the next one when the first says no.

:::note{title="What you'll need"}
-   The spec for each destination: its address, the fields it expects and any key it gave you.
-   One real reply from each destination, or the example in its spec.
-   A form, if you want to finish with a real lead. You can do everything else without one. See
    [Your first website form](https://www.eventsiq.io/docs/website-form).
:::

:::tip{title="No partner to test with yet?"}
On the first screen of **New destination**, pick **A test destination**. It sends to a safe echo
address and never counts as a sale, so you can watch a lead go through and move on to the next
destination. It is named `Test destination: always declines` until you rename it.
:::

## Step 1: Add your first destination

Go to **Destinations** and click **New destination**. It asks one thing at a time, and nothing is
saved until the last screen.

1. Under **Start from**, pick **Blank**.
2. Under **Name**, type something your team will recognise, for example `Roofing Partner A`. The
   destination never sees this name.
3. Under **How does the partner take leads?**, pick **Post** unless their spec asks for a ping first.
   In that case pick **Ping/Post**.
4. Click **Next: where to send**. Copy the **Method**, **Address** and **Send as** from their spec.
   If they gave you a key or password, click **Add it as a secret header**.
5. Click **Next: what to send**. The rows start with the fields most partners ask for. Rename each
   one to match their spec.
6. Click **Next: when it is sold**.

## Step 2: Set what a sale looks like

EventsIQ reads each reply and decides whether the lead was sold. If you skip this step, any 2xx
reply counts as a sale and sales carry no price, so Reports show no revenue for them.

1. Under **Their reply**, enter the **Status** and paste the **Body**, for example:

   ```json
   {"status": "accepted", "price": 42.5}
   ```

2. Click **Save reply**. EventsIQ lists the fields it found in the reply.
3. Hover over `status` and click **+** to add a check. Hover over `price` and click **$** to use it
   as the sale price.

![Pasting their reply](https://www.eventsiq.io/docs-media/destinations/destinations-tester.png "A destination's Sale and price tab with a sample reply pasted into Their reply, above Sold when, and for how much. The same editor appears in this step.")

The checks appear under **Sold when, and for how much**. You can also click **Add check** and fill
one in by hand. A sentence below the rule says it in words, for example **The lead is sold when the
status is any 2xx, and status is accepted.**

![Sold when, and for how much](https://www.eventsiq.io/docs-media/destinations/destinations-accept-rule.png "Sold when, and for how much, with Accepted status codes, one check, and What the lead sold for set to From the reply.")

Read that sentence before you go on, then:

1. Click **Next: check and create**.
2. Check the summary and click **Create destination**.
3. If you have no routing setup yet, click **Not now**.

## Step 3: Add the second destination

The quickest way is to copy the first one.

1. Go back to **Destinations** and click **New destination**.
2. Under **Start from**, pick **A copy of a destination** and choose `Roofing Partner A`. It copies
   the address, fields, sale rule and limits. Nothing stays linked afterwards.
3. Change the **Name** to `Roofing Partner B`.
4. Click **Next: where to send** and change the **Address**. Replace any secret header if this
   destination gave you its own key.
5. Click through **What to send** and **When it is sold**, changing anything that differs. Replace
   the saved reply with one from this destination.
6. Click **Create destination**, then **Not now**.

If the two specs are very different, pick **Blank** and repeat steps 1 and 2 instead.

## Step 4: Put them in order

1. Go to **Routing** and click **New routing**.
2. Type a **Name**, for example `Roofing - all leads`, and click **Create routing**. It starts paused,
   so nothing is sent until you go live.
3. Find **Everything else**. It takes every lead that no branch has matched, and with no branches
   yet, that is every lead.
4. Under **Add a destination**, pick `Roofing Partner A`, then `Roofing Partner B`.

The destination at the top is offered the lead first. Drag them to change the order. Changes save
automatically.

## Step 5: Test a lead

Start with a dry run. It sends nothing to any destination, logs nothing and does not count against
a cap.

1. Click **Test a lead** at the top of the routing setup. The **Test** tab opens on the right.
2. Keep **Type answers** selected and enter some answers under **Answers, as JSON**:

   ```json
   {
       "firstname": "Jamie",
       "lastname": "Carter",
       "phone": "+15125550123",
       "state": "TX"
   }
   ```

3. Click **Run test**. You should see **No branch matched.**, then both destinations in order under
   **Offered to, in order**.

![The Test tab](https://www.eventsiq.io/docs-media/routing/routing-test.png "A routing setup's Test tab with sample answers and the result, No branch matched, so Everything else takes the lead. Names are samples.")

Next, check what each destination would receive:

1. Go to **Destinations**, open `Roofing Partner A` and click the **Test** tab.
2. Keep **An invented lead** selected and click **Run practice**.
3. **A lead like this would be sent** means the request is ready. Below it you should see **Their
   saved reply would sell it for 42.5**, and under **The request**, exactly what would be sent.

Nothing leaves EventsIQ during a practice run. Repeat it for `Roofing Partner B`.

When both look right, send one real lead:

:::important{title="This one is real"}
From here the lead goes to each destination's real address. Use details you are happy for them to
receive, and tell them you are testing.
:::

1. Open your routing setup, click the **Forms** tab on the right and choose your form under **Add a
   form**.
2. Click **Go live** at the top.
3. Fill in the form yourself.
4. Go to **Activity → Lead logs** and open the lead. **What happened, in order** lists each
   destination that was offered the lead and what it replied.

:::tip{title="You're done when"}
The lead's row in **Lead logs** shows **Sold** under **What happened** and `Roofing Partner A` under **Sold
to**. Open it and the first line reads **Sold to Roofing Partner A for** its price, and **What
happened, in order** shows **Roofing Partner A bought it**, tagged **Sold**. Nobody below it was
called.
:::

### Optional: watch a lead pass down the order

To see what happens when the first destination says no, without involving a second real partner:

1. Create **A test destination** (see the tip at the top) and click **Not now** at the end.
2. In your routing setup, add it under **Everything else** and drag it to the top, above
   `Roofing Partner A`.
3. Fill in the form again.
4. Open the new lead in **Lead logs**. **What happened, in order** shows the test destination
   **declined it**, tagged **Declined**, then **Roofing Partner A bought it**, tagged **Sold**.
5. Take the test destination out of **Everything else** again.

The lead still goes to `Roofing Partner A`, so the same rule applies: use details you are happy for
them to receive.

## Troubleshooting

:::warning{title="Leads show as sold, but the destination did not take them"}
-   The destination replies `200` even when it declines, and the rule has no checks. Add a check
    under **And the reply says**.
-   The check reads the wrong field. Save a real reply and pick the field from the list rather than
    typing it.
:::

:::warning{title="Go live does nothing, or says to fix problems first"}
The line at the top of the routing setup, and the **Checks** tab, list what is stopping it. **This
routing has nowhere to send leads** means **Everything else** is still empty.
:::

:::warning{title="The lead is saved but never offered to anyone"}
-   The routing setup is still **Paused**. Leads are stored, but nothing is sent.
-   The form is not attached. Check the **Forms** tab.
-   **Taking leads** is switched off on the destination, so it is skipped.
-   A field marked **Must have** was empty. The log names the field.
:::

:::warning{title="The first destination never takes a lead"}
Open the lead in **Activity → Lead logs** and read the reply under **What happened, in order**. It
says which part of the rule failed, for example that a field had a different value from the one
expected.
:::

## Where to go next

-   [Route leads by state](https://www.eventsiq.io/docs/guide-route-by-state): send each state to the destinations that serve it.
-   [Report sales from your CRM](https://www.eventsiq.io/docs/guide-crm-postbacks): tell the ad network when a lead closes.
-   [Destinations](https://www.eventsiq.io/docs/destinations): ping/post, formats, known errors and every other setting.
-   [Routing](https://www.eventsiq.io/docs/routing): branches, events, checks and overrides.
