Skip to main content

n8n Integration

Overview

n8n is a powerful open-source automation platform that allows users to create, deploy, and manage complex workflows through a visual interface. It supports integration with over 300 applications and services and offers various trigger methods such as webhooks and scheduled triggers.

The bidirectional integration between OneAI and n8n provides users with powerful automation capabilities:

  1. OneAI calling n8n workflows: Through the skill plugin mechanism, n8n workflows are extended as OneAI capabilities, enabling AI to trigger and execute complex automation processes for data processing, system integration, and more.
  2. n8n calling OneAI API: Seamlessly invoke OneAI’s intelligent services within n8n workflows, injecting AI capabilities into automation processes such as text analysis, content generation, and knowledge Q&A.

This bidirectional integration offers enterprises flexible automation solutions applicable to customer service automation, data processing workflows, cross-system business process orchestration, intelligent notifications, and more, helping improve operational efficiency and reduce manual costs.

n8n Calling OneAI API

Install OneAI Community Node

Enter the settings page via the bottom left corner of the n8n workspace ... > Setting, and install n8n-nodes-oneai under Community nodes:

tip

Please restart the n8n service after installing the community node; otherwise, duplicate OneAI nodes may appear in the node panel.

Add OneAI Credential

In the Add Credential interface, select OneAI.

Fill in the following information:

  • Base URL: OneAI server address, without a trailing /
  • Client ID: Created and obtained via OneAI’s Client Management
  • Client Secret: Created and obtained via OneAI’s Client Management
  • User Account: Corresponding user name in user management; API calls will be made under this user identity. Ensure the user has sufficient API permissions.

After saving, the credential will be automatically tested. If configured correctly, it will display Connection tested successfully:

Method 1: Call OpenAPI via OneAI Node

Select the OneAI node:

Choose the Action to execute:

Test the node:

  1. Configure appropriate parameters
  2. Click the "Test Step" button to execute the test
  3. View the execution result in the right panel

Specific test steps:

  • Confirm the correct OneAI Credential is selected
  • Fill in the necessary input parameters
  • Execute the node and verify if the returned result meets expectations
  • If execution fails, check error messages and adjust configuration accordingly

Method 2: Call OpenAPI via HTTP Request Node

The OneAI Node currently only provides some OpenAPI operations. If the required API is not in the OneAI Node’s operation list, you can use the HTTP Request Node to call the API directly.

Select the HTTP Request node:

Configure request parameters:

  • Method: Select the appropriate HTTP method (GET/POST/PUT, etc.)
  • URL: Fill in the full URL path of the OneAI API
  • Headers: Add request headers as needed
  • Query Parameters/Body: Configure according to API requirements
tip

You can import via cURL, but be sure to remove the Authorization header; otherwise, it will conflict with the Authentication configuration below.

Configure Authentication:

  • Authentication: Select Predefined Credential Type
  • Credential Type: Select OneAI API
  • OneAI API: Choose an existing OneAI Credential or create a new one

Test the node:

  1. Confirm all parameters are correctly configured
  2. Click the "Execute Node" button to run the test
  3. Check if the returned result meets expectations

OneAI Calling n8n Workflow

Create n8n Workflow

First, create a workflow named Echo and set the Trigger to Webhook. After creation, click the "Active" button at the top right to activate the workflow.

Configure the Webhook:

  • HTTP Method: Select POST
  • Path: The address to call this workflow; the default value can be used
  • Authentication: Select Header Auth and create Credential; save the Header and Value for later use in skill plugin configuration
  • Respond: Select Using 'Respond to Webhook' Node

Add the Respond to Webhook node and configure as follows:

  • Respond With: Select JSON
  • Response Body: Switch from Fixed to Expression and enter the following JSON:
{
"output": "{{ $json.body.input }}"
}

Add Skill and Associate with n8n Workflow

Complete the following configuration on the OneAI platform:

  • Code: Enter echo
  • Name: Enter echo, click the magic wand for automatic translation
  • Description: Enter echo, click the magic wand for automatic translation
  • Request header: If Header Auth was set in the previous n8n webhook, add the corresponding Header and Value here to ensure interface authentication passes
  • OpenAPI / Swagger Schema (JSON): Modify based on the following template:
tip

Replace {n8n_server_url} with the URL of the n8n server, and {n8n_webhook_path} with the path of the n8n webhook node.

{
"openapi": "3.0.3",
"info": {
"title": "N8N echo example",
"version": "1.0.0"
},
"servers": [
{
"url": "{n8n_server_url}"
}
],
"paths": {
"/webhook/{n8n_webhook_path}": {
"post": {
"operationId": "echo",
"summary": "echo",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "Text content from user input"
}
},
"required": [
"input"
]
}
}
}
},
"responses": {
"200": {
"description": "Echo success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"output": {
"type": "string",
"description": "Echo output"
}
},
"required": [
"output"
]
}
}
}
}
}
}
}
}
}

After configuration, you can click the "debug" button to test:

Call Skill via Agent

Add the echo skill to the Agent:

Modify the Agent’s Prompt to guide skill invocation.

Prompt example:

# Skill echo

If the user enters the `echo` command, please call the `echo` function and return `output` in the result.

Test the skill (input echo 1+1=?, return 1+1=?, and you can see the echo skill being called):

Check the n8n workflow execution status:

More complex workflows can be extended based on this example.

For example: To query a database via n8n and return data, add a Database node between the Webhook and Respond to Webhook nodes and configure the database connection information. Then adjust the Respond to Webhook’s Body value accordingly to correctly return the queried data.

Best Practices and Troubleshooting

Best Practices

  • Write clear comments and descriptions for each workflow
  • Use appropriate error handling mechanisms to ensure workflow stability
  • Regularly check workflow execution history and logs
  • For complex workflows, it is recommended to validate in a test environment first

Common Issues and Troubleshooting

  1. Authentication Failure

    • Check if Credential configuration is correct
    • Confirm Client ID and Secret are valid
    • Verify the user account has sufficient permissions
  2. Webhook Call Failure

    • Ensure the n8n service is accessible from the OneAI server
    • Check if authentication header information is correctly configured
    • Verify the webhook path is correct
  3. Node Execution Errors

    • Check if input data format meets requirements
    • Confirm API version compatibility
    • Review detailed error log information

Deploying n8n

n8n provides deployment documentation for various environments. You can refer to n8n self-hosted deployment to choose the deployment method that suits you best.

If you want to quickly deploy n8n on the Azure platform and are familiar with Terraform, the following script is provided for your reference:

main.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "4.27.0"
}
}
}

provider "azurerm" {
features {}
subscription_id = var.subscription_id
tenant_id = var.tenant_id
}

# Variable definitions
variable "subscription_id" {
description = "Azure Subscription ID"
type = string
default = "your-subscription-id"
}

variable "tenant_id" {
description = "Azure Tenant ID"
type = string
default = "your-tenant-id"
}

variable "application_name" {
description = "Application name"
type = string
default = "n8n"
}

variable "environment" {
description = "Environment"
type = string
default = "dev"
}

variable "location" {
description = "Azure region"
type = string
default = "eastasia"
}

variable "container_image" {
description = "N8N container image"
type = string
default = "n8nio/n8n:latest"
}

variable "n8n_host" {
description = "N8N URL"
type = string
default = "your-app-url.azurewebsites.net"
}

variable "random_suffix" {
description = "Random string"
type = string
default = "suffix"
}

variable "app_service_sku" {
description = "App Service Plan SKU"
type = string
default = "B2"
}

# Account and password variables
variable "n8n_encryption_key" {
description = "N8N encryption key"
type = string
default = "your-encryption-key"
sensitive = true
}

variable "n8n_basic_auth_user" {
description = "N8N basic auth username"
type = string
default = "admin"
}

variable "n8n_basic_auth_password" {
description = "N8N basic auth password"
type = string
default = "your-secure-password"
sensitive = true
}

variable "postgresql_admin_username" {
description = "PostgreSQL admin username"
type = string
default = "psqladmin"
}

variable "postgresql_admin_password" {
description = "PostgreSQL admin password"
type = string
default = "your-secure-password"
sensitive = true
}

# Resource Group
resource "azurerm_resource_group" "n8n" {
name = "rg-${var.application_name}-${var.environment}"
location = var.location
}

# App Service Plan
resource "azurerm_service_plan" "n8n" {
name = "asp-${var.application_name}-${var.environment}"
resource_group_name = azurerm_resource_group.n8n.name
location = azurerm_resource_group.n8n.location
os_type = "Linux"
sku_name = var.app_service_sku
}

# App Service (Web App for Containers)
resource "azurerm_linux_web_app" "n8n" {
name = "app-${var.application_name}-${var.environment}-${var.random_suffix}"
resource_group_name = azurerm_resource_group.n8n.name
location = azurerm_resource_group.n8n.location
service_plan_id = azurerm_service_plan.n8n.id

app_settings = {
"N8N_ENCRYPTION_KEY" = var.n8n_encryption_key
"N8N_HOST" = "${var.n8n_host}"
"N8N_PORT" = "443"
"N8N_PROTOCOL" = "https"
"N8N_WEBHOOK_URL" = "https://${var.n8n_host}/"
"GENERIC_TIMEZONE" = "Asia/Shanghai"
"N8N_BASIC_AUTH_ACTIVE" = "true"
"N8N_BASIC_AUTH_USER" = var.n8n_basic_auth_user
"N8N_BASIC_AUTH_PASSWORD" = var.n8n_basic_auth_password
"EXECUTIONS_DATA_PRUNE" = "true"
"EXECUTIONS_DATA_MAX_AGE" = "336"
"WEBSITES_PORT" = "443"

# DB Config
"DB_TYPE" = "postgresdb"
"DB_POSTGRESDB_HOST" = "${azurerm_postgresql_flexible_server.postgresql_server.fqdn}"
"DB_POSTGRESDB_PORT" = "5432"
"DB_POSTGRESDB_DATABASE" = "${azurerm_postgresql_flexible_server_database.postgresql_database.name}"
"DB_POSTGRESDB_USER" = var.postgresql_admin_username
"DB_POSTGRESDB_PASSWORD" = var.postgresql_admin_password
"DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED" = "false"
}

site_config {
always_on = true
websockets_enabled = true

application_stack {
docker_image_name = "${var.container_image}"
docker_registry_url = "https://docker.n8n.io"
}
}
}

# PostgreSQL database server
resource "azurerm_postgresql_flexible_server" "postgresql_server" {
name = "psql-${var.application_name}-${var.environment}"
resource_group_name = azurerm_resource_group.n8n.name
location = azurerm_resource_group.n8n.location
administrator_login = var.postgresql_admin_username
administrator_password = var.postgresql_admin_password

version = "16"
sku_name = "B_Standard_B1ms"
# 128GB
storage_mb = 131072

backup_retention_days = 35
geo_redundant_backup_enabled = true

public_network_access_enabled = true

lifecycle {
ignore_changes = [
zone,
]
}
}

# PostgreSQL firewall rule
resource "azurerm_postgresql_flexible_server_firewall_rule" "postgresql_firewall_rule" {
name = "AllowAzureServicesAccessPGSQL"
server_id = azurerm_postgresql_flexible_server.postgresql_server.id
start_ip_address = "0.0.0.0"
end_ip_address = "0.0.0.0"
}

# PostgreSQL database instance
resource "azurerm_postgresql_flexible_server_database" "postgresql_database" {
name = "psqldb-${var.application_name}-${var.environment}"
server_id = azurerm_postgresql_flexible_server.postgresql_server.id
charset = "UTF8"
collation = "en_US.utf8"
}

# Output
output "n8n_url" {
description = "N8N access url"
value = "https://${azurerm_linux_web_app.n8n.default_hostname}"
}

References