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

# n8n Overview

Automate Sitecopilot with **n8n**. Use built‑in HTTP nodes (no plugin required) or an optional helper module (**Sitecopilot SuperTool**) to simplify common actions. This overview covers capabilities, install, structure, and best practices.

> All examples use JSON over HTTPS and Bearer tokens.

## What you can automate

* **Pages** — list, create, delete (`GET/POST/DELETE /api/pages|/api/page`).
* **Content** — update templates & banner (`PUT /api/content`).
* **Assets** — upload media (`POST /api/asset`).
* **Settings** — analytics code, noindex, statistics iframe (`POST /api/settings`).
* **Sitemap** — fetch JSON (`POST /api/sitemap`).
* **Notifications** — send status to the editor UI (`POST /api/notifications`).
* **AI‑assisted flows** — send page context to Sitecopilot Cloud and apply the returned proposal.

## Two API surfaces

* **Central (Admin)** — tenant lifecycle & tokens.
* **Tenant (Site)** — content, assets, settings, notifications, sitemap, chatbot.

Create **two credentials** in n8n (recommended):

* `SITECOPILOT_ADMIN_BASE_URL` + `SITECOPILOT_ADMIN_TOKEN`
* `SITECOPILOT_TENANT_BASE_URL` + `SITECOPILOT_TENANT_TOKEN`

## Install paths (no custom node required)

Use native n8n nodes:

* **HTTP Request** — API calls (header `Authorization: Bearer <TOKEN>`)
* **Cron** — schedules
* **Webhook** — inbound triggers
* **Code** — compose payloads

This is the simplest, fully supported approach.

## Optional helper: Sitecopilot SuperTool

A small JS module wrapping common API calls.

### Download & place

1. Download `sitecopilot-supertool.js` from your repository.
2. Put it in the **custom folder** of your n8n instance:

* Docker/K8s: `/home/node/.n8n/custom/sitecopilot/sitecopilot-supertool.js`
* Linux: `~/.n8n/custom/sitecopilot/sitecopilot-supertool.js`
* macOS Desktop: `~/Library/Application Support/n8n/custom/sitecopilot/sitecopilot-supertool.js`

3. **Restart** n8n to make it available to Code nodes.

> This module is imported by a **Code** node. For a visual palette node, package it later as a Community Node.

### Use from a Code node

```js theme={null}
import { sitecopilotSuperTool } from './custom/sitecopilot/sitecopilot-supertool.js';


const token = $env.SITECOPILOT_TENANT_TOKEN;
const baseUrl = $env.SITECOPILOT_TENANT_BASE_URL; // e.g. https://tenant.example.com


const out = await sitecopilotSuperTool({ action: 'listPages', token, baseUrl });
return [{ out }];
```

### Supported actions (extendable)

* `listPages`, `createPage`, `deletePage`
* `updateContent`
* `uploadAsset`
* `updateSettings`
* `getVariables`, `updateVariable`, `deleteVariable` *(if enabled)*

## Error handling & retries

* 4xx: fix input (validation/auth). 5xx: retry with backoff.
* Use n8n node **retry** + **error branch** for alerts.
* Log `error`, `message`, and `details` when present.

## Security & secrets

* Store tokens as **Credentials** or **Environment variables** (never hard‑code in nodes).
* Use separate creds for **Central** vs **Tenant**.
* Rotate tokens and apply rate limits.
