Skip to content

API 身份验证#

¥API authentication

n8n 使用 API 密钥对 API 调用进行身份验证。

¥n8n uses API keys to authenticate API calls.

Feature availability

n8n API 在免费试用期间不可用。请升级以使用此功能。

¥The n8n API isn't available during the free trial. Please upgrade to access this feature.

API 作用域#

¥API Scopes

企业实例 的用户可以使用权限范围限制密钥可以访问的资源和操作。API 密钥作用域允许你指定密钥在其预期用途所需的精确访问级别。

¥Users of enterprise instances can limit which resources and actions a key can access with scopes. API key scopes allow you specify the exact level of access a key needs for its intended purpose.

非企业级 API 密钥拥有对账户所有资源和功能的完全访问权限。

¥Non-enterprise API keys have full access to all the account's resources and capabilities.

创建 API 密钥#

¥Create an API key

  1. 登录到 n8n

¥Log in to n8n. 2. 前往“设置”>“n8n API”。

¥Go to Settings > n8n API. 3. 选择“创建 API 密钥”。

¥Select Create an API key. 4. 选择标签并设置键的过期时间。

¥Choose a Label and set an Expiration time for the key. 5. 如果你使用的是企业版套餐,请选择要提供密钥的作用域。

¥If on an enterprise plan, choose the Scopes to give the key. 6. 复制我的 API 密钥,并使用此密钥验证你的调用。

¥Copy My API Key and use this key to authenticate your calls.

使用你的密钥调用 API#

¥Call the API using your key

在 API 调用中以名为 X-N8N-API-KEY 的标头发送 API 密钥。

¥Send the API key in your API call as a header named X-N8N-API-KEY.

例如,假设你想要获取所有活动工作流。你的 curl 请求将如下所示:

¥For example, say you want to get all active workflows. Your curl request will look like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# For a self-hosted n8n instance
curl -X 'GET' \
  '<N8N_HOST>:<N8N_PORT>/<N8N_PATH>/api/v<version-number>/workflows?active=true' \
  -H 'accept: application/json' \
  -H 'X-N8N-API-KEY: <your-api-key>'

# For n8n Cloud
curl -X 'GET' \
  '<your-cloud-instance>/api/v<version-number>/workflows?active=true' \
  -H 'accept: application/json' \
  -H 'X-N8N-API-KEY: <your-api-key>'

删除 API 密钥#

¥Delete an API key

  1. 登录到 n8n

¥Log in to n8n. 2. 前往“设置”>“n8n API”。

¥Go to Settings > n8n API. 3. 选择要删除的键旁边的“删除”。

¥Select Delete next to the key you want to delete. 4. 确认删除操作,选择“永久删除”。

¥Confirm the delete by selecting Delete Forever.