# Webhooks

> Get call results pushed to your system after each call, and start journeys from your system with a signed webhook.

URL: https://docs.lemuai.com/api-reference/webhooks
For: Developers
Checked against LemuAI app version 1.0.12
Related: [Webhook](https://docs.lemuai.com/voice-agent/webhook), [Journey Nodes & Triggers](https://docs.lemuai.com/automation/nodes-and-triggers), [Send an Event](https://docs.lemuai.com/api-reference/events/trigger), [Journeys](https://docs.lemuai.com/troubleshooting/journeys)

There are two directions:

| Direction | What | Set up in |
|---|---|---|
| LemuAI → you | After each call, a voice agent sends the result (variables it captured, duration, recording, transcript) to your URL | A **Webhook** step in the voice agent |
| You → LemuAI | Your system starts a journey for someone by posting to the journey's webhook URL | A journey with the **Webhook** trigger |

To send events (orders, sign-ups) that start any journey listening for them, use [Send an Event](https://docs.lemuai.com/api-reference/events/trigger) instead; it needs your API key and links the event to a contact.

## Receive call results

Add a **Webhook** step to the voice agent (**Voice Agents → Agents**, open the agent). Set the **HTTP Method**, **Endpoint URL**, optional **Auth** and **Custom Headers**, and a **Payload Template (JSON)** using these variables:

| Variable | Value |
|---|---|
| `{{workflow_run_id}}` | The call's run id |
| `{{workflow_id}}`, `{{workflow_name}}` | The agent |
| `{{initial_context.<name>}}` | Values the call started with (from the API, a journey or a campaign) |
| `{{gathered_context.<name>}}` | Variables the agent extracted |
| `{{cost_info.call_duration_seconds}}` | Call duration |
| `{{recording_url}}`, `{{transcript_url}}` | Recording and transcript links |

Example payload template:
```json
{
  "call_id": "{{workflow_run_id}}",
  "order_id": "{{initial_context.order_id}}",
  "confirmed": "{{gathered_context.confirmed}}",
  "duration": "{{cost_info.call_duration_seconds}}",
  "recording_url": "{{recording_url}}"
}
```

Your endpoint should answer with a `2xx` status quickly. See [Webhook (voice agent)](https://docs.lemuai.com/voice-agent/webhook).

## Start a journey with a webhook

Create a journey with the **Webhook** trigger. Its panel shows the URL to post to:
```text
POST https://app.lemuai.com/api/v1/workflow-execution/webhooks/{trigger_id}
```

The JSON body becomes the run's starting context, so later steps can use `{{context.<field>}}`. Include the person's `phone` so steps that call or message have someone to reach. No API key is needed: the URL is the secret. For extra safety, set a **secret** on the trigger and sign each request.

### Signing requests

When the trigger has a secret, every request must carry:
```text
X-Webhook-Signature: sha256=<hex HMAC-SHA256 of the raw request body, keyed with the secret>
```

Sign the exact bytes you send. Re-serialising the JSON after signing (different spacing or key order) breaks the signature.

**cURL**

```bash
BODY='{"phone":"+919876543210","order_id":"A-1001","amount":1499}'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | sed 's/^.* //')
curl -X POST "https://app.lemuai.com/api/v1/workflow-execution/webhooks/123" \
  -H "Content-Type: application/json" \
  -H "X-Webhook-Signature: sha256=$SIG" \
  --data-raw "$BODY"
```

**JavaScript**

```js
import crypto from "node:crypto";

const body = JSON.stringify({ phone: "+919876543210", order_id: "A-1001", amount: 1499 });
const sig = crypto.createHmac("sha256", process.env.WEBHOOK_SECRET).update(body).digest("hex");

const res = await fetch("https://app.lemuai.com/api/v1/workflow-execution/webhooks/123", {
  method: "POST",
  headers: { "Content-Type": "application/json", "X-Webhook-Signature": `sha256=${sig}` },
  body,
});
console.log(res.status, await res.json());
```

**Python**

```python
import hashlib, hmac, json, os, requests

body = json.dumps({"phone": "+919876543210", "order_id": "A-1001", "amount": 1499}).encode()
sig = hmac.new(os.environ["WEBHOOK_SECRET"].encode(), body, hashlib.sha256).hexdigest()

r = requests.post(
    "https://app.lemuai.com/api/v1/workflow-execution/webhooks/123",
    data=body,
    headers={"Content-Type": "application/json", "X-Webhook-Signature": f"sha256={sig}"},
    timeout=30,
)
print(r.status_code, r.json())
```

### Responses

| Status | Meaning |
|---|---|
| `200` | The run started. The body includes the trigger and run details |
| `401` | "Invalid webhook signature": missing or wrong `X-Webhook-Signature` |
| `404` | "Trigger {id} not found": the trigger was deleted, or the id is wrong |
| `400` | "Trigger {id} is not active", "Trigger {id} is not a webhook trigger", a request that doesn't match the trigger's settings (method, content type, required headers), or a journey that isn't live |

See [Journeys troubleshooting](https://docs.lemuai.com/troubleshooting/journeys) for each message.
