> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.rasen.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.rasen.ai/_mcp/server.

# Send call results to n8n

> Receive the summary of each finished call in an n8n workflow, with a verified signature, a fast answer and no duplicates.

## Summary

This recipe sends the summary of each finished call from Rasen to an n8n workflow through a
signed `call.analyzed` webhook. The workflow verifies the signature, answers `2xx` at once, drops
duplicates and reads the summary from the API when the event does not carry it. It does not cover
what you do with the summary after that, for example writing it to a sheet or a CRM.

## Facts

| Item                          | Value                                                                                                                                                                                                                                                                                                                                    |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Result                        | One n8n item for each analyzed call, with `call_id`, `summary_state` and `summary`                                                                                                                                                                                                                                                       |
| Rasen operations              | `createWebhookEndpoint`, `sendWebhookTestEvent`, `getCall`, `getCallSummary`, `listWebhookDeliveries`                                                                                                                                                                                                                                    |
| Rasen paths                   | `POST /webhook-endpoints`, `POST /webhook-endpoints/{endpoint_id}/test`, `GET /calls/{call_id}`, `GET /calls/{call_id}/summary`, `GET /webhook-endpoints/{endpoint_id}/deliveries`                                                                                                                                                       |
| Capability                    | `webhooks.manage` for the endpoint operations; `calls.read` for `getCall` and `getCallSummary`                                                                                                                                                                                                                                           |
| Required headers              | `Authorization` on every request; `Idempotency-Key` on create and test                                                                                                                                                                                                                                                                   |
| Event                         | `call.analyzed`: once for each call that got `call.completed`, when the transcript, recording state and extraction are final, or 6 hours after the call ended                                                                                                                                                                            |
| Summary in the event          | `data.summary` is what `getCallSummary` returns when Rasen builds the event, or `null`. The event does not wait for the summary                                                                                                                                                                                                          |
| Reduced event                 | A body over 1 MiB carries only `data.call_id` and `data.truncated: true`                                                                                                                                                                                                                                                                 |
| Attempt timeout               | 10 seconds for each attempt. Any `2xx` answer is a success; a `3xx` answer or a timeout fails the attempt                                                                                                                                                                                                                                |
| Attempts                      | Up to 8. Waits between attempts: 5 seconds, 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours, 10 hours, each ±10%                                                                                                                                                                                                                       |
| Call event window             | Rasen creates a call's end event only within 24 hours of the call end                                                                                                                                                                                                                                                                    |
| Delivery                      | At least once, with the same `webhook-id` and body on every attempt and resend. No ordering guarantee                                                                                                                                                                                                                                    |
| Signature                     | `webhook-signature` holds one or two `v1,<base64 HMAC-SHA256>` values over `{webhook-id}.{webhook-timestamp}.{body}`. The key is the base64-decoded part of the secret after `whsec_`                                                                                                                                                    |
| Timestamp window              | Refuse a `webhook-timestamp` more than 5 minutes from your clock                                                                                                                                                                                                                                                                         |
| Endpoint `url`                | `https`, with a host that resolves only to public addresses. Redirects are never followed                                                                                                                                                                                                                                                |
| n8n version                   | n8n 2.x, self-hosted or n8n Cloud                                                                                                                                                                                                                                                                                                        |
| n8n nodes                     | Webhook, Code, If, Respond to Webhook, Remove Duplicates, HTTP Request                                                                                                                                                                                                                                                                   |
| n8n Webhook node              | **Production URL** registers when you publish the workflow. **Respond**: `Using 'Respond to Webhook' Node`. Option **Raw Body** puts the exact request bytes in the binary property `data`                                                                                                                                               |
| n8n Code node                 | JavaScript, mode **Run Once for All Items**. `this.helpers.getBinaryDataBuffer(0, 'data')` reads the raw body. n8n Cloud allows `require('crypto')`; self-hosted n8n needs `NODE_FUNCTION_ALLOW_BUILTIN=crypto`                                                                                                                          |
| Where the signing secret goes | Self-hosted n8n, any edition: an environment variable of the n8n server, read as `$env.RASEN_WEBHOOK_SECRET`. n8n 2.x blocks `$env` in nodes unless the server sets `N8N_BLOCK_ENV_ACCESS_IN_NODE=false`. n8n Cloud Pro and Enterprise, and self-hosted Business and Enterprise: a custom variable, read as `$vars.RASEN_WEBHOOK_SECRET` |
| n8n Remove Duplicates node    | **Remove Items Processed in Previous Executions** keeps a history of 10,000 items by default                                                                                                                                                                                                                                             |
| Environment for the samples   | `RASEN_API_BASE` (the base URL, ending in `/v1`), `RASEN_API_KEY`, `N8N_WEBHOOK_URL`, `ENDPOINT_ID`, `CALL_ID`                                                                                                                                                                                                                           |
| Python                        | 3.10 or later, with the `httpx` package                                                                                                                                                                                                                                                                                                  |
| TypeScript                    | Node.js 22 or later (built-in `fetch`)                                                                                                                                                                                                                                                                                                   |

## Steps

### 1. Create the n8n Webhook node

1. In n8n, create a workflow and add a **Webhook** node.
2. Set **HTTP Method** to `POST` and **Path** to `call-results`.
3. Set **Authentication** to `None`. The signature check in step 3 authenticates each request.
4. Set **Respond** to `Using 'Respond to Webhook' Node`.
5. Under **Options**, add **Raw Body** and turn it on.
6. Publish the workflow, then copy the **Production URL** of the node.

The Production URL has the form `https://<your n8n host>/webhook/call-results`. Set
`N8N_WEBHOOK_URL` to it. The **Test URL** listens for 120 seconds only, so do not register it with
Rasen.

### 2. Register a Rasen webhook endpoint for `call.analyzed`

**`curl`**

```bash curl
curl -sS -X POST "$RASEN_API_BASE/webhook-endpoints" \
  -H "Authorization: Bearer $RASEN_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"url\": \"$N8N_WEBHOOK_URL\", \"description\": \"n8n call results\", \"events\": [\"call.analyzed\"]}"
```

**`Python`**

```python Python
import os
import uuid

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]
N8N_WEBHOOK_URL = os.environ["N8N_WEBHOOK_URL"]

response = httpx.post(
    f"{BASE}/webhook-endpoints",
    headers={"Authorization": f"Bearer {KEY}", "Idempotency-Key": str(uuid.uuid4())},
    json={"url": N8N_WEBHOOK_URL, "description": "n8n call results", "events": ["call.analyzed"]},
)
response.raise_for_status()
endpoint = response.json()
print(endpoint["id"], endpoint["state"])
print(endpoint["secret"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, N8N_WEBHOOK_URL } = process.env;

const response = await fetch(`${RASEN_API_BASE}/webhook-endpoints`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${RASEN_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ url: N8N_WEBHOOK_URL, description: "n8n call results", events: ["call.analyzed"] }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const endpoint = await response.json();
console.log(endpoint.id, endpoint.state);
console.log(endpoint.secret);
```

The answer is `201` with the endpoint and its signing `secret`. No other answer returns the secret,
so store it at once. Set `ENDPOINT_ID` to the `id` of the endpoint.

Store the secret where your n8n edition can read it:

* Self-hosted n8n: add these lines to the environment of the n8n server, then restart n8n.

  ```bash
  RASEN_WEBHOOK_SECRET=<the secret from this answer>
  NODE_FUNCTION_ALLOW_BUILTIN=crypto
  N8N_BLOCK_ENV_ACCESS_IN_NODE=false
  ```

  `N8N_BLOCK_ENV_ACCESS_IN_NODE=false` lets every workflow read every environment variable of the
  server. Give edit access to workflows only to people who may read the secret.
* n8n Cloud, or a licensed self-hosted edition: create a custom variable named
  `RASEN_WEBHOOK_SECRET` with the secret as its value. In step 3, read
  `$vars.RASEN_WEBHOOK_SECRET` instead of `$env.RASEN_WEBHOOK_SECRET`.

The endpoint receives only events that Rasen creates after the endpoint's `created_at`.

### 3. Verify the signature and answer in n8n

Add a **Code** node after the Webhook node. Name it `Verify signature`, set **Language** to
JavaScript and **Mode** to **Run Once for All Items**, and paste this code:

```javascript
const crypto = require('crypto');

const TOLERANCE_SECONDS = 5 * 60;
const secret = $env.RASEN_WEBHOOK_SECRET; // n8n Cloud or a licensed edition: $vars.RASEN_WEBHOOK_SECRET
const headers = $input.first().json.headers;
const body = await this.helpers.getBinaryDataBuffer(0, 'data');

function verify() {
  const webhookId = headers['webhook-id'];
  const timestamp = headers['webhook-timestamp'];
  const signatures = headers['webhook-signature'];
  if (!secret || !webhookId || !timestamp || !/^[0-9]{1,12}$/.test(timestamp) || !signatures) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) return false;
  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
  const expected = crypto.createHmac('sha256', key).update(`${webhookId}.${timestamp}.`).update(body).digest();
  return signatures.split(' ').some((value) => {
    const [version, signature] = value.split(',', 2);
    if (version !== 'v1' || !signature) return false;
    const given = Buffer.from(signature, 'base64');
    return given.length === expected.length && crypto.timingSafeEqual(given, expected);
  });
}

const valid = verify();
return [{ json: { valid, event: valid ? JSON.parse(body.toString('utf8')) : null } }];
```

The code checks the exact request bytes before it parses the JSON. Then add these nodes:

| Node                                    | Name                | Settings                                                                                                                                             |
| --------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| If                                      | `Signature valid?`  | Condition: `{{ $json.valid }}` is true                                                                                                               |
| Respond to Webhook, on the false output | `Reject`            | **Respond With**: `No Data`. Option **Response Code**: `401`                                                                                         |
| Respond to Webhook, on the true output  | `Accept`            | **Respond With**: `No Data`. Option **Response Code**: `200`                                                                                         |
| Remove Duplicates, after `Accept`       | `Drop repeats`      | **Operation**: `Remove Items Processed in Previous Executions`. **Keep Items Where**: `Value Is New`. **Value to Dedupe On**: `{{ $json.event.id }}` |
| If, after `Drop repeats`                | `Is call.analyzed?` | Condition: `{{ $json.event.type }}` is equal to `call.analyzed`                                                                                      |
| Code, on the true output                | `Pick summary`      | The code below                                                                                                                                       |

`Accept` answers Rasen before any slow node runs. The workflow then goes on with the event. A
`webhook.test` event passes the signature check, gets `200`, and stops at `Is call.analyzed?`.

Paste this code into `Pick summary`, with **Mode** set to **Run Once for All Items**:

```javascript
const event = $input.first().json.event;
const data = event.data;
const callId = data.truncated ? data.call_id : data.call.id;
const summary = data.truncated ? null : data.summary;
return [{
  json: {
    event_id: event.id,
    call_id: callId,
    summary_state: summary ? summary.state : null,
    summary: summary && summary.state === 'ready' ? summary.summary : null,
    end_reason: data.truncated ? null : data.call.end_reason,
  },
}];
```

### 4. Read the summary when the event does not carry it

Add an **If** node named `Summary ready?` after `Pick summary`, with the condition
`{{ $json.summary_state }}` is equal to `ready`. On its false output, add an **HTTP Request**
node named `Read summary`:

| Setting            | Value                                                                                                              |
| ------------------ | ------------------------------------------------------------------------------------------------------------------ |
| **Method**         | `GET`                                                                                                              |
| **URL**            | `<RASEN_API_BASE>/calls/{{ $json.call_id }}/summary`, with your API base URL ending in `/v1`                       |
| **Authentication** | `Generic Credential Type`, then `Header Auth`, with **Name** `Authorization` and **Value** `Bearer <your API key>` |

These requests show what `Read summary` sends, with `getCall` for the call fields of a reduced
event. Set `CALL_ID` to the `call_id` of the item.

**`curl`**

```bash curl
curl -sS "$RASEN_API_BASE/calls/$CALL_ID" \
  -H "Authorization: Bearer $RASEN_API_KEY"

curl -sS "$RASEN_API_BASE/calls/$CALL_ID/summary" \
  -H "Authorization: Bearer $RASEN_API_KEY"
```

**`Python`**

```python Python
import os

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]
CALL_ID = os.environ["CALL_ID"]
AUTH = {"Authorization": f"Bearer {KEY}"}

call = httpx.get(f"{BASE}/calls/{CALL_ID}", headers=AUTH)
call.raise_for_status()
print(call.json()["end_reason"], call.json()["summary_state"])

summary = httpx.get(f"{BASE}/calls/{CALL_ID}/summary", headers=AUTH)
summary.raise_for_status()
result = summary.json()
print(result["state"], result["summary"], result["poll_after_seconds"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, CALL_ID } = process.env;
const auth = { Authorization: `Bearer ${RASEN_API_KEY}` };

const call = await fetch(`${RASEN_API_BASE}/calls/${CALL_ID}`, { headers: auth });
if (!call.ok) throw new Error(`HTTP ${call.status}`);
const callBody = await call.json();
console.log(callBody.end_reason, callBody.summary_state);

const summary = await fetch(`${RASEN_API_BASE}/calls/${CALL_ID}/summary`, { headers: auth });
if (!summary.ok) throw new Error(`HTTP ${summary.status}`);
const result = await summary.json();
console.log(result.state, result.summary, result.poll_after_seconds);
```

`getCallSummary` answers the summary with its `state`. `summary` holds text only when `state` is
`ready`. While `state` is `pending`, wait `poll_after_seconds` (an n8n **Wait** node,
**Resume** `After Time Interval`) and read it again. `not_requested`, `failed` and `unavailable` do
not change into `ready` on their own: store the item with `summary` `null`.

### 5. Send a test event

**`curl`**

```bash curl
curl -sS -X POST "$RASEN_API_BASE/webhook-endpoints/$ENDPOINT_ID/test" \
  -H "Authorization: Bearer $RASEN_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

**`Python`**

```python Python
import os
import uuid

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]
ENDPOINT_ID = os.environ["ENDPOINT_ID"]

response = httpx.post(
    f"{BASE}/webhook-endpoints/{ENDPOINT_ID}/test",
    headers={"Authorization": f"Bearer {KEY}", "Idempotency-Key": str(uuid.uuid4())},
)
response.raise_for_status()
delivery = response.json()
print(delivery["id"], delivery["event_type"], delivery["state"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, ENDPOINT_ID } = process.env;

const response = await fetch(`${RASEN_API_BASE}/webhook-endpoints/${ENDPOINT_ID}/test`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${RASEN_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const delivery = await response.json();
console.log(delivery.id, delivery.event_type, delivery.state);
```

The answer is `201` with the queued delivery of one `webhook.test` event, signed like every other
event. In n8n, open the **Executions** tab of the workflow. The execution passes `Verify signature`
with `valid: true` and ends at `Is call.analyzed?`.

## Rules

* MUST register the Production URL, and MUST publish the workflow before Rasen sends events.
* MUST verify the signature over the raw body bytes before you parse or use the event.
* MUST answer `2xx` within 10 seconds. Put `Accept` before every slow node.
* MUST answer `401` or another status that is not `2xx` when the signature check fails.
* MUST drop repeats by the event `id`, which equals the `webhook-id` header. Rasen delivers at
  least once.
* MUST read the call with `getCall` and `getCallSummary` when `data.truncated` is `true`.
* MUST answer `2xx` to an event `type` that you do not know, and ignore it.
* MUST NOT store the signing secret in a node parameter that people who edit the workflow can read
  in plain text. Use a server environment variable (self-hosted), a custom variable (licensed
  editions) or your secret store.
* After `Accept` answers `2xx`, Rasen does not send the event again. If a later node fails, resend
  the delivery with `resendWebhookDelivery`, or read the call with `getCall`.

## Verify

```bash
curl -sS -G "$RASEN_API_BASE/webhook-endpoints/$ENDPOINT_ID/deliveries" \
  -H "Authorization: Bearer $RASEN_API_KEY" \
  --data-urlencode "event_type=webhook.test" \
  --data-urlencode "state=succeeded"
```

Expected output: at least one item with `"state": "succeeded"` and `"last_status_code": 200`.

```json
{"items": [{"id": "wdl_01j00000000000000000000000", "event_type": "webhook.test", "call_id": null, "state": "succeeded", "attempt_count": 1, "max_attempts": 8, "last_status_code": 200, "last_error_class": null}], "next_cursor": null}
```

## Errors

| Code                                                  | Cause                                                                                                 | Fix                                                                                              |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `outbound_destination_refused`                        | The n8n URL is not `https`, or its host does not resolve only to public addresses                     | Expose n8n on a public `https` host, then register its Production URL                            |
| `invalid_request`                                     | The `url` has user information or a fragment, or `events` repeats a value                             | Fix the field in `details.field` and send the request with a new `Idempotency-Key`               |
| `conflict` (`details.reason: endpoint_limit_reached`) | The workspace has 10 endpoints that are not deleted                                                   | Delete an endpoint, or add `call.analyzed` to an existing endpoint with `replaceWebhookEndpoint` |
| `conflict` (`details.reason: endpoint_disabled`)      | The test event targets an endpoint in `state: disabled` or `disabled_failing`                         | Enable the endpoint with `replaceWebhookEndpoint` and `"enabled": true`                          |
| `forbidden`                                           | The key lacks `webhooks.manage` or `calls.read`                                                       | Use a key with the capability in `details.required_capabilities`                                 |
| `not_found`                                           | The endpoint or call does not exist in this workspace                                                 | Check `ENDPOINT_ID` with `listWebhookEndpoints`, or `CALL_ID` with `listCalls`                   |
| `last_error_class: http_status` on a delivery         | n8n answered a status that is not `2xx`: the workflow is not published, or the signature check failed | Publish the workflow, and check `RASEN_WEBHOOK_SECRET` against the endpoint's `secret_hint`      |
| `access to env vars denied` in the n8n execution      | n8n 2.x blocks `$env` in nodes                                                                        | Set `N8N_BLOCK_ENV_ACCESS_IN_NODE=false` on the n8n server, and restart n8n                      |
| `last_error_class: timeout` on a delivery             | n8n did not answer within 10 seconds                                                                  | Move `Accept` directly after `Signature valid?`                                                  |

## Related

* [Receive call events with webhooks](/guides/webhooks)
* [Webhook events](/reference/webhook-events)
* [Place calls and read results](/guides/calls)
* [Troubleshoot a call](/guides/troubleshoot-calls)
* [Limits and quotas](/concepts/limits)