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

# n8n

> Connect an assistant to your n8n workflows with Klatt webhooks, to look up data during a conversation or to be notified when it ends.

You can connect an assistant to n8n in two ways:

* **Recipe A**: the assistant asks n8n for data during the conversation, for example to look up an order.
* **Recipe B**: Klatt notifies n8n when the conversation ends, with its summary.

No n8n node is needed. The recipes use n8n's [Webhook node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook/) and Klatt [webhooks](https://docs.klatt.ai/voice-agent/webhooks.md).

## With your AI assistant

You can ask an assistant connected to [Klatt's MCP](https://docs.klatt.ai/api-reference/mcp.md) to create the webhook for you. For example:

> Connect my n8n workflow at `<production URL>` to my Klatt assistant `<assistant>`, to look up an order by its number, with a custom header credential and no key. Read Klatt's n8n guide first.

The assistant reads this guide and creates the webhook without the key. If it chose an API key, Klatt stores it as **Custom header**, with the header name it gave or `X-Webhook-Key`.

1. Open the link the assistant gives you, press **Generate key** in **Authentication**, and copy the key.
2. In n8n, set the Webhook node's **Header Auth** credential to that header name, and paste the key as its value.

Never give the key to the assistant, in the chat or anywhere else.

## Recipe A: the assistant asks n8n during the conversation

1. In n8n, add a **Webhook** node.
   * Set the same method as in Klatt. Use `GET` for lookups.
   * Set the authentication to **Header Auth**, or **Basic Auth**. Create the [credential](https://docs.n8n.io/integrations/builtin/credentials/webhook/) with a header name such as `X-Webhook-Key` and a secret value, for example `<your-secret>`.
   * Set **Respond** to **Using 'Respond to Webhook' Node**.
2. Add a [Respond to Webhook](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.respondtowebhook/) node at the end of the workflow. Respond with a **JSON** object that has only the fields the assistant needs, for example `{"status": "shipped", "deliveryDate": "2026-11-04"}`.
3. Publish the workflow and copy its **Production URL**, for example `https://your-n8n.example.com/webhook/order-status`. The Test URL only works while the n8n editor is listening, so do not use it in Klatt.
4. In Klatt, open the assistant. In **General**, under **Abilities**, open **Webhooks** and select **Add webhook**. Set **When it runs** to **During the conversation**.
5. Fill in the webhook.
   * **Method** and **URL**: the Production URL. Put the data the assistant asks for in the query as `{{name}}`, for example `https://your-n8n.example.com/webhook/order-status?orderId={{orderId}}`.
   * **When should the assistant use it?**: which customer question triggers the lookup and what the assistant must ask first.
   * **Data the assistant asks for**: add `orderId`, with a description and a test value. Put example values in **Test value**, not in the description: the assistant may send an example from the description instead of what the customer says.
   * **Authentication**: **Custom header**, with the same header name and value as your n8n Header Auth credential. For n8n Basic Auth, choose **Username and password** instead. Put the secret in **Authentication** or in a locked (secret) header, never in a plain header or in the URL.
6. Select **Test request**. The result must show the JSON that n8n returned.

See [Webhooks](https://docs.klatt.ai/voice-agent/webhooks.md#during-the-conversation) for the variables, limits and what the assistant does with the answer.

### Requests that change data

On voice, a request that changes data during a call (POST, PUT, PATCH or DELETE) needs caller verification and the caller's spoken confirmation. See [Safety](https://docs.klatt.ai/voice-agent/webhooks.md#safety). On WhatsApp, the assistant asks the customer to confirm, and sends a POST during the conversation once they agree in their next message.

## Recipe B: Klatt notifies n8n when the conversation ends

1. In n8n, add a **Webhook** node with method `POST` and the same **Header Auth** setup as in Recipe A.
   * If your workflow is slow, set **Respond** to **Immediately**, so Klatt gets its answer fast.
   * Delivery is at least once. Use the `Idempotency-Key` header to skip a delivery you already processed.
   * To check that a request really comes from Klatt, see [Verify the signature](#verify-the-signature).
2. Publish the workflow and copy its **Production URL**.
3. In Klatt, open **Webhooks** in the assistant's **Abilities**, select **Add webhook** and set **When it runs** to **At the end**.

   * **URL**: the Production URL.
   * **Authentication**: the same as in n8n.
   * **Body**: keep the default, or send only what you need, for example `summary`, `durationSeconds`, `disconnectReason` and `personNumber`:

   ```json theme={null}
   {
     "summary": "{{summary}}",
     "durationSeconds": "{{durationSeconds}}",
     "disconnectReason": "{{disconnectReason}}",
     "personNumber": "{{personNumber}}"
   }
   ```
4. Optional: in **Advanced**, **Only if…**, write a condition such as "the customer promised a payment". The request is only sent when it is true of the conversation.
5. Select **Test request**. It sends an example conversation, so you can see what n8n receives. A test carries `X-Klatt-Test: 1` and no `Idempotency-Key`.
6. Optional: sign the requests and check the signature in n8n (see [Verify the signature](#verify-the-signature)).

See [Webhooks](https://docs.klatt.ai/voice-agent/webhooks.md#at-the-end) for when the request is sent, retries and the full list of variables.

### Verify the signature

A signature proves that the request came from Klatt, that its body was not changed and that it is not an old request sent again. See [Signature](https://docs.klatt.ai/voice-agent/webhooks.md#signature) for how it works.

1. In Klatt, in the webhook's **Advanced** tab, select **Generate secret** under **Signing secret**, copy the secret and save the webhook.
2. In n8n, open the **Webhook** node. In **Options**, turn on **Raw Body**, so n8n keeps the body exactly as Klatt sent it.
3. Add a **Code** node right after it, in **Run Once for All Items** mode, with this code. Replace `whsec_...` with your secret:

   ```js theme={null}
   const crypto = require('crypto');
   const SECRET = 'whsec_...';

   const headers = $input.first().json.headers;
   const body = await this.helpers.getBinaryDataBuffer(0, 'data');
   const id = headers['webhook-id'];
   const timestamp = headers['webhook-timestamp'];

   const key = Buffer.from(SECRET.slice('whsec_'.length), 'base64');
   const expected = crypto.createHmac('sha256', key).update(`${id}.${timestamp}.`).update(body).digest();
   const valid = String(headers['webhook-signature'] || '').split(' ').some((entry) => {
     const [version, signature] = entry.split(',');
     const given = Buffer.from(signature || '', 'base64');
     return version === 'v1' && given.length === expected.length && crypto.timingSafeEqual(given, expected);
   });
   if (!valid || !(Math.abs(Date.now() / 1000 - Number(timestamp)) <= 300)) {
     throw new Error('Invalid Klatt signature');
   }

   return [{ json: { webhookId: id, ...JSON.parse(body.toString('utf8')) } }];
   ```

   The node stops the workflow when the signature is wrong or the request is more than 5 minutes old. Otherwise it passes on the body's fields and `webhookId`.
4. To process each delivery once, add a **Remove Duplicates** node with **Remove Items Processed in Previous Executions**, **Keep Items Where** set to **Value Is New**, and `webhookId` as **Value to Dedupe On**.
5. Select **Test request** in Klatt. It is signed with the secret in the sheet, and its `webhookId` starts with `test_`.

The secret is part of the workflow, so anyone who can edit the workflow can read it. On n8n Cloud the Code node can use `crypto`. On a self-hosted n8n, allow it with the environment variable `NODE_FUNCTION_ALLOW_BUILTIN=crypto`.

## Example: debt collection

This example uses both recipes. The assistant checks a debt during the call, and n8n records the outcome afterwards. It is written for a voice assistant. On WhatsApp, `personNumber` is the sender's number; read [Safety](https://docs.klatt.ai/voice-agent/webhooks.md#safety) before you return personal data with a `GET`, and note that the request at the end is sent when the conversation closes (see [At the end](https://docs.klatt.ai/voice-agent/webhooks.md#at-the-end)).

* **Who is on the phone.**
  * For a campaign that calls the assistant's contact list, with a smart field such as "Debt reference", send `{{contact.debt_reference}}`. n8n finds the debt by reference instead of by number. See [Contact data](https://docs.klatt.ai/voice-agent/webhooks.md#contact-data).
  * When the number is not in the assistant's contact list, or on incoming calls, contact variables are empty. n8n identifies the debtor by `personNumber` and looks the number up in your own system.
* **Look up the debt (Recipe A, `GET`).**
  * Tell the assistant, in **When should the assistant use it?**, to ask for a verification datum that only the debtor knows before it calls n8n, for example the debt reference or the postal code. Add `reference` under **Data the assistant asks for**, with no example value in its description.
  * Send both in the query. For a campaign with a smart field, use the reference from the list: `https://your-n8n.example.com/webhook/debt?debt_reference={{contact.debt_reference}}&postalCode={{postalCode}}`, with `postalCode` under **Data the assistant asks for**. Otherwise identify the debtor by number: `https://your-n8n.example.com/webhook/debt?phone={{personNumber}}&reference={{reference}}`.
  * In n8n, return the amount and the due date only when the debt is found and the verification datum matches.
  * When they do not match, return `{"verified": false}` and no other data. Limit failed attempts per number in n8n, because a caller can try several references.
  * Why: whoever answers the phone may not be the debtor. A `GET` on voice runs without caller verification unless you add it in **Advanced**; here the check in n8n does that job.
* **Record the outcome (Recipe B).**
  * In the assistant's **Abilities**, open **Capture data** and add two fields: `promised_amount` (type **Number**) and `promised_date` (type **Date**). In each description, say what Klatt should look for, for example "the amount the customer promises to pay".

  * In **Advanced**, use **Only if…**, and send `personNumber`, `summary`, `disconnectReason`, `{{outcome.promised_amount}}` and `{{outcome.promised_date}}`, so n8n knows whose outcome it is. For a campaign with a smart field, add `{{contact.debt_reference}}` to the body:

    ```json theme={null}
    {
      "personNumber": "{{personNumber}}",
      "summary": "{{summary}}",
      "disconnectReason": "{{disconnectReason}}",
      "promisedAmount": "{{outcome.promised_amount}}",
      "promisedDate": "{{outcome.promised_date}}"
    }
    ```

  * The amount arrives as a number and the date as `YYYY-MM-DD`. Either can be `null` when the customer did not say it, so write them in your system only when they are not `null`.
* **What this does not do.** It does not record the promise during the call. That needs a request that changes data during a voice call, with caller verification (see [Safety](https://docs.klatt.ai/voice-agent/webhooks.md#safety)).
* **Testing.** The console's test call and test chat have no number, so a URL with `{{personNumber}}` or `{{contact.debt_reference}}` fails there. **Test request** sends an example number and an example value for each contact variable. Change them in the test values. It only finds a debt if your test data uses those values; otherwise expect `{"verified": false}`. Test the whole flow with a real call.
* **Personal data.**
  * The amount, the summary and the transcript are personal data. Ask only for the fields you need, and leave the transcript out of the body unless you need it.
  * n8n keeps the data of each execution. Set how long it is kept, and how it is deleted, in n8n.
  * This is not legal advice.

## Troubleshooting

* **The request never reaches the workflow.** Use the Production URL, not the Test URL, and publish the workflow. The method in Klatt must match the method of the **Webhook** node; otherwise n8n answers with a 404.
* **The server cannot be reached.** Klatt only calls public HTTPS addresses on port 443, and does not follow redirects. A self-hosted n8n on port `:5678` or on `localhost` does not work. Put it behind HTTPS on the standard port.
* **Timeouts and odd answers.** Klatt waits 5 seconds by default; raise **Maximum wait** in **Advanced** up to 30 seconds if n8n needs longer. Answer with a small JSON object. **Respond to Webhook** sends text as `text/html` by default, so respond with JSON.
* **500 errors.** If the workflow fails before it reaches **Respond to Webhook**, n8n answers with a 500. Klatt treats it as a server error.
* **n8n rejects the request.** With Header Auth, n8n answers with a 403 and `Authorization data is wrong!`. Check that the header name and value in **Authentication** (or in your secret header) match the n8n credential exactly. **Test request** shows the status n8n returned.
* **JWT or n8n User Auth.** Klatt does not sign JWTs or get n8n User Auth tokens. Use Header Auth or Basic Auth.


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