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

# n8n

> Use NewLead in your workflows with the official node.

> [!WARNING]
>
> Version 2 of the node cannot be used as a tool of an AI agent. In that mode a retry could send the message twice.

## Install the node

**1. Open community nodes**

In n8n, go to **Settings** > **Community Nodes** and select **Install**.

**2. Install the package**

Enter `n8n-nodes-newlead` and confirm.

## Connect your account

**1. Create an API key**

In the NewLead dashboard, open the subaccount and create a key in **Settings › API**.

**2. Create the credential**

In n8n, create a **Newlead API** credential and paste the key.

**3. Keep the base URL**

Leave **Base URL** as `https://rest.newlead.ai`.

The node needs a subaccount key. An organization key fails the credential test.

> [!NOTE]
>
> Workflows saved before version 2 keep running on version 1. To move them, follow [Migrate from the legacy routes](https://docs.newlead.ai/migrate-legacy-routes.md#n8n-node).

## Operations

| Resource | Operations |
| - | - |
| **Template** | **Send** an approved WhatsApp template |
| **Message** | **Send** a text message to a lead |
| **Lead** | **Create**, **Get**, **Get Many** and **Update**; with **Agent Type** › **Voice**, the leads of a voice agent |
| **AI Control** | **Pause**, **Resume** and **Get Status** |
| **Call** | **Start**, **Get**, **Get Many** and **Get Recording** |
| **Property** | **Get by Reference**, **Get Many**, **Create or Update** and **Delete** |

## Send messages

> [!WARNING]
>
> Include the country code in every phone number: `+34600111222`. A local number such as `600111222` returns an error, because the node does not guess the country.

**Message** > **Send** writes to a lead that already exists. To reach a new number, use **Template** > **Send**, which creates the lead.

* **From the list or by ID:** the node checks that the lead belongs to the selected agent. If it does not, the node returns an error and sends nothing.
* **By phone number:** the node searches only WhatsApp and Meta Ads leads of the selected agent. A web chat lead with the same number does not count. If no lead matches, or more than one does, the node returns an error and sends nothing.

## Voice calls

**Call** > **Start** makes a voice agent call a number. **Lead Name** and **Lead Variables** are saved on the lead before dialing, and the agent uses them during the call. Every call carries an `Idempotency-Key`, like the sends.

**Call** > **Get Recording** returns the audio as a binary file in the `data` field. The node downloads it from a signed link that expires in one hour, and does not send your API key there.

To read the leads of a voice agent, set **Lead** > **Agent Type** to **Voice**. The list only shows voice agents without a text agent: a voice agent linked to a text agent shares that agent's leads, so choose **Text** and the text agent.

## Properties from your CRM

**Property** > **Create or Update** creates a property with your reference, or replaces the one that has it: a field you leave empty is cleared. **Property** > **Delete** removes it by reference. Both only change properties created through the API, never the ones imported from Idealista. To keep a whole catalog in sync, follow [Website properties](https://docs.newlead.ai/website-properties.md).

## Send in bulk

The API allows 120 requests per minute per key. **Message** > **Send** uses two requests per item, and **Template** > **Send** uses one.

For bulk sends, use **Loop Over Items** with **Wait** and set your own **Idempotency Key**. Running the workflow again after a `429` then skips the messages that already went out.

## Retry without sending twice

* **Retry On Fail** reuses the same key within an execution, so a retry normally does not send twice.
* Running a finished execution again generates new keys.

> [!WARNING]
>
> Running a finished execution again sends the messages again, unless you set a stable **Idempotency Key** in the options of **Template** > **Send**, **Message** > **Send** or **Call** > **Start**.

Make the key different for each send, not only for each recipient: for example, the record ID in your CRM plus the reason for the message. The API remembers it for [24 hours](https://docs.newlead.ai/idempotency.md#key-rules).

## Handle errors

With **Settings** > **On Error** > **Continue**, the error item carries `error` and `details`:

```json theme={null}
{
  "error": "The send may have gone out",
  "details": {
    "code": "send_outcome_unknown",
    "request_id": "req_m3k2a9_4f1c2b7e",
    "outcome_unknown": true,
    "description": "Check whether it was delivered before repeating it, and do not repeat it with a different idempotency key. Request ID: req_m3k2a9_4f1c2b7e."
  }
}
```

If `details.outcome_unknown` is `true`, the message may have gone out. Check the lead's messages before you repeat it, and do not repeat it with a different key. All the codes are in [Errors](https://docs.newlead.ai/errors.md#error-codes).

## Receive events

Add the **Newlead Trigger** node, choose the agent and the events, and activate the workflow. The node subscribes itself in NewLead, verifies the [signature](https://docs.newlead.ai/webhook-signatures.md) of every delivery and unsubscribes when you deactivate the workflow.

* Your n8n needs a public `https` URL. If it runs behind a proxy, set `WEBHOOK_URL` to that address.
* The API key needs a role that can manage agents.
* Each agent takes up to 3 active endpoints. Listening for a test event in the editor uses one while it listens.
* Each item carries `delivery_id`, the same on every retry. To skip repeats, add **Remove Duplicates** with **Remove Items Processed in Previous Executions** on that field.
* Publishing a change to the trigger subscribes it again, with a new secret. If NewLead [pauses the endpoint](https://docs.newlead.ai/webhooks.md) after many failed deliveries in a row, turn it back on in the agent's Webhooks panel.


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