REST API
Relevant source files
The following files were used as context for generating this wiki page:
- packages/cli/src/public-api/v1/openapi.yml
- packages/cli/src/controllers/workflows.controller.ts
- packages/cli/src/controllers/credentials.controller.ts
- packages/cli/src/controllers/executions.controller.ts
- packages/frontend/@n8n/rest-api-client/package.json
- packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json
- packages/nodes-base/nodes/Webhook/Webhook.node.json
- packages/nodes-base/nodes/GraphQL/GraphQL.node.json
The n8n REST API provides a programmatic interface for interacting with the n8n backend. It allows users and external systems to manage core resources such as workflows, credentials, and executions. The API is built on standard REST principles, using HTTP requests and returning JSON-formatted responses. Its structure and endpoints are formally defined in an OpenAPI v3 specification, ensuring a clear and consistent contract for developers.
This API is not only for external use but is also consumed by the n8n frontend application, which leverages a dedicated client package, @n8n/rest-api-client, to communicate with the backend. In addition to its own management API, n8n provides powerful nodes like the HTTP Request and Webhook nodes, which allow workflows to consume any external REST API or create new API endpoints to trigger automations.
Sources: packages/cli/src/public-api/v1/openapi.yml, packages/frontend/@n8n/rest-api-client/package.json:2, packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json:2, packages/nodes-base/nodes/Webhook/Webhook.node.json:2
API Architecture
The n8n API follows a standard client-server model. The backend, built with NestJS, exposes a set of controllers that handle incoming HTTP requests for different resources. The frontend interacts with this API via the @n8n/rest-api-client package, which is an Axios-based client.
Sources: packages/frontend/@n8n/rest-api-client/package.json:30, packages/cli/src/controllers/workflows.controller.ts
The diagram below illustrates the high-level architecture of the n8n REST API interaction.
This diagram shows clients (external systems or the n8n frontend) making requests to the REST API, which are routed to the appropriate controllers for processing.
API Specification (OpenAPI)
The public REST API is formally defined using the OpenAPI 3.0 specification. This definition serves as the single source of truth for all available endpoints, their parameters, request bodies, and response schemas.
Sources: packages/cli/src/public-api/v1/openapi.yml:2-3
Example: Workflow Deletion Endpoint
The following YAML snippet from the OpenAPI specification defines the endpoint for deleting a workflow. It specifies the path (/workflows/{id}), the HTTP method (delete), a summary, tags, parameters, and possible responses.
/workflows/{id}:
delete:
summary: Delete a workflow
tags:
- Workflows
operationId: deleteWorkflow
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: Workflow deleted
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Workflow with id "1" has been deleted.
Sources: packages/cli/src/public-api/v1/openapi.yml:111-133
Core API Endpoints
The API is organized around core n8n resources. The main controllers handle logic for workflows, credentials, and executions.
Sources: packages/cli/src/controllers/workflows.controller.ts, packages/cli/src/controllers/credentials.controller.ts, packages/cli/src/controllers/executions.controller.ts
Workflows
The WorkflowsController manages all operations related to workflows, such as creation, retrieval, updates, and activation.
Sources: packages/cli/src/controllers/workflows.controller.ts
The following sequence diagram shows the interaction for fetching a single workflow.
This diagram illustrates a client requesting a workflow by its ID, the API server routing the request to the WorkflowsController, and the controller returning the workflow data.
Workflow API Endpoints
| Method | Path | Description | Controller Method |
|---|---|---|---|
POST | /workflows | Create a new workflow. | create() |
GET | /workflows | Get all workflows. | findAll() |
GET | /workflows/{id} | Get a single workflow by ID. | findOne() |
PUT | /workflows/{id} | Update a workflow. | update() |
DELETE | /workflows/{id} | Delete a workflow. | remove() |
POST | /workflows/{id}/activate | Activate a workflow. | activate() |
POST | /workflows/{id}/deactivate | Deactivate a workflow. | deactivate() |
Sources: packages/cli/src/controllers/workflows.controller.ts:25-90, packages/cli/src/public-api/v1/openapi.yml:71-150
Credentials
The CredentialsController is responsible for managing user credentials in a secure manner.
Sources: packages/cli/src/controllers/credentials.controller.ts
Credential API Endpoints
| Method | Path | Description | Controller Method |
|---|---|---|---|
POST | /credentials | Create a new credential. | create() |
GET | /credentials | Get all credentials. | findAll() |
GET | /credentials/{id} | Get a single credential by ID. | findOne() |
PUT | /credentials/{id} | Update a credential. | update() |
DELETE | /credentials/{id} | Delete a credential. | remove() |
Sources: packages/cli/src/controllers/credentials.controller.ts:24-69, packages/cli/src/public-api/v1/openapi.yml:15-69
Executions
The ExecutionsController provides access to the history of workflow executions.
Sources: packages/cli/src/controllers/executions.controller.ts
Execution API Endpoints
| Method | Path | Description | Controller Method |
|---|---|---|---|
GET | /executions | Get all executions. | findAll() |
GET | /executions/{id} | Get a single execution by ID. | findOne() |
DELETE | /executions/{id} | Delete an execution. | remove() |
Sources: packages/cli/src/controllers/executions.controller.ts:23-53, packages/cli/src/public-api/v1/openapi.yml:152-192
Interacting with APIs via Nodes
n8n's core strength is its ability to connect different services, many of which are exposed via REST APIs. This is accomplished through a set of powerful, built-in nodes.
Consuming External APIs: HTTP Request Node
The HTTP Request node is a versatile tool for making requests to any REST or HTTP-based API. It allows users to configure the method, URL, headers, body, and authentication, making it the "Swiss Army Knife" for API integration within a workflow. It is aliased with terms like API, Request, and cURL.
Sources: packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json:2,20
Creating API Endpoints: Webhook Node
The Webhook node allows a workflow to be triggered by an incoming HTTP request. When a Webhook node is added to a workflow, n8n generates a unique URL. Sending a GET or POST request to this URL will trigger the workflow, passing the request's headers, query parameters, and body as starting data. This effectively allows users to create their own custom API endpoints to start automations.
Sources: packages/nodes-base/nodes/Webhook/Webhook.node.json:2,44
The following flowchart shows the process of a workflow being triggered by a webhook.
This diagram shows an external service sending a request to a unique n8n webhook URL, which triggers the corresponding workflow and makes the request data available to the following nodes.
Specialized API Nodes
In addition to generic tools, n8n also offers specialized nodes for interacting with specific types of APIs, such as the GraphQL node for GraphQL APIs.
Sources: packages/nodes-base/nodes/GraphQL/GraphQL.node.json:2
Summary
The n8n REST API provides comprehensive, programmatic control over the platform's core resources, defined by a clear OpenAPI specification. This enables deep integration with external systems and custom tooling. Internally, the API is consumed by the n8n frontend via a dedicated client. Furthermore, n8n empowers users to build powerful automations by providing flexible nodes like HTTP Request and Webhook to interact with any external API and to create custom endpoints, making it a central hub for API-driven workflow automation.
Sources: packages/cli/src/public-api/v1/openapi.yml, packages/frontend/@n8n/rest-api-client/package.json, packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json, packages/nodes-base/nodes/Webhook/Webhook.node.json