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

# Connect to n8n

> Call V5 Gateway tools from n8n workflows via REST API

## Overview

n8n is a consumer of the V5 Gateway — it calls the REST API (not MCP) to trigger tools from workflow nodes. Use this pattern when you need event-driven or scheduled triggering without a human in the loop.

<Note>
  n8n **does not** connect via MCP. It calls the V5 REST API (`POST /api/v1/{tenant}/{domain}`) using an HTTP Request node.
</Note>

## Prerequisites

* n8n Cloud or self-hosted n8n
* A V5 bearer token (stored as an n8n credential)
* Tenant ID (e.g. `kahuna`)

## Setting up the credential

In n8n, create a **Generic Credential** (or Header Auth credential):

```
Name: V5 Gateway
Header Name: Authorization
Header Value: Bearer <your-token>
```

## Making a tool call

Use an **HTTP Request** node:

| Field          | Value                                                               |
| -------------- | ------------------------------------------------------------------- |
| Method         | `POST`                                                              |
| URL            | `https://ascend-gateway-v5.ascendgtm.workers.dev/api/v1/kahuna/crm` |
| Authentication | Generic Credential → *V5 Gateway*                                   |
| Body           | JSON (see below)                                                    |

**Example body — fetch HubSpot contacts:**

```json theme={null}
{
  "tool": "hubspot_crm",
  "input": {
    "action": "list_contacts",
    "limit": 50,
    "filter": {
      "property": "createdate",
      "operator": "GT",
      "value": "{{ $now.minus(7, 'days').toMillis() }}"
    }
  }
}
```

## Workflow patterns

### Event-triggered enrichment

```
Webhook (new contact in HubSpot)
  → HTTP Request (V5: perplexity_search for company data)
  → HTTP Request (V5: hubspot_crm update with enriched data)
  → Slack notification
```

### Daily report

```
Schedule (every weekday 08:00)
  → HTTP Request (V5: google_ads_query for yesterday's spend)
  → HTTP Request (V5: ga4_report for conversions)
  → Code node (calculate ROAS)
  → HTTP Request (V5: aws_ses_send email to team)
```

### Human-in-the-loop approval

```
HTTP Request (V5: google_ads_query — large budget change)
  → IF node (budget change > $5,000)
    → Slack (ask Mishaal for approval)
    → Wait node (webhook response)
    → HTTP Request (V5: google_ads mutate — apply change)
```

## REST API vs MCP

|                | REST API (for n8n)      | MCP (for Claude/Cursor) |
| -------------- | ----------------------- | ----------------------- |
| Protocol       | HTTP POST               | Streamable HTTP         |
| Auth           | Bearer token header     | OAuth 2.1 or Bearer     |
| Best for       | Event-driven, scheduled | Interactive, agentic    |
| Tool selection | Caller specifies tool   | AI chooses tool         |

## Troubleshooting

**401 Unauthorized** — Check the credential header. It must be `Authorization: Bearer <token>`, not `x-api-key`.

**TENANT\_NOT\_FOUND** — Verify the tenant ID in the URL path matches your provisioned tenant.

**UPSTREAM\_ERROR** — The upstream API (HubSpot, Google) rejected the request. Check the `error_detail` in the response body.
