Skip to main content

Quick Start

n8n-client is easiest to understand if you think in three steps:

  1. Create N8nClient with your n8n base URL and one authentication method.
  2. Pick a typed handle such as workflow(), execution(), or project().
  3. Call methods that map directly to the public API without hand-writing HTTP requests.

Installation

npm install @egose/n8n-client --save

Authentication

The n8n Public API supports two authentication methods: API key and Bearer token.

Use exactly one of them. The client rejects configurations that provide both or neither.

import N8nClient from '@egose/n8n-client';

const client = new N8nClient({
baseUrl: 'http://localhost:5678',
apiKey: 'your-n8n-api-key', // pragma: allowlist secret
});

Bearer Token (JWT)

const client = new N8nClient({
baseUrl: 'http://localhost:5678',
bearerToken: 'your-jwt-token',
});

First Script

This is the smallest useful script for checking that your instance URL, credentials, and client setup are correct:

import N8nClient from '@egose/n8n-client';

const client = new N8nClient({
baseUrl: 'http://localhost:5678',
apiKey: process.env.N8N_API_KEY!,
});

const { data: workflows } = await client.workflow().list({ limit: 5 });

for (const workflow of workflows) {
console.log(`${workflow.id} ${workflow.name}`);
}

Basic Usage

List Workflows

const { data: workflows, nextCursor } = await client.workflow().list({
limit: 10,
active: true,
});

Get a Workflow

const workflow = await client.workflow().get('workflow-id');
console.log(workflow.name, workflow.active);

Create a Credential

const credential = await client.credential().create({
name: 'My API Key',
type: 'httpHeaderAuth',
data: {
headerName: 'Authorization',
headerValue: 'Bearer secret-token',
},
});

Manage Executions

// List error executions
const { data: errors } = await client.execution().list({
status: 'error',
workflowId: 'workflow-id',
});

// Stop a running execution
await client.execution().stop(executionId);

How The API Surface Is Organized

  • Use client.workflow() for workflow lifecycle and tagging.
  • Use client.execution() for monitoring, retrying, and stopping runs.
  • Use client.project() and client.folder(projectId) for structure and access control.
  • Use client.get(), client.post(), and the other low-level helpers only when you intentionally need to drop below a typed handle.

Organize with Projects

await client.project().create({ name: 'Production' });

await client.project().addMembers('project-id', [
{ userId: 'user-id', role: 'project:admin' },
]);

Resource Handles

Every n8n API resource has a typed handle:

HandleAccessDescription
WorkflowHandleclient.workflow()Create, list, activate, archive workflows
ExecutionHandleclient.execution()List, get, stop, retry executions
CredentialHandleclient.credential()CRUD, test, transfer credentials
TagHandleclient.tag()Manage workflow/execution tags
UserHandleclient.user()List, create, delete users
VariableHandleclient.variable()Manage environment variables
ProjectHandleclient.project()CRUD projects and members
DataTableHandleclient.dataTable()Tables, columns, and rows
FolderHandleclient.folder(projectId)Project-scoped folder management
CommunityPackageHandleclient.communityPackage()Install, update, uninstall packages
AuditHandleclient.audit()Generate audit reports
InsightsHandleclient.insights()Execution insights summary
SourceControlHandleclient.sourceControl()Git-based source control
DiscoverHandleclient.discover()Discover available resources
N8nPackageHandleclient.n8nPackage()Import/export workflow packages

Next Steps

  • Browse the API Reference for the full method surface.
  • Read Philosophy if you want the design rationale behind handles, retries, and low-level request helpers.
  • Check out Examples for end-to-end walkthroughs.