很多初学者在刚接触 n8n 时,能画出漂亮的工作流,但一运行就报错——401 Unauthorized。别慌,这通常是因为你没有给 n8n 也就是工作流的“通行证”(Credentials)。
今天我们就来攻克这个关卡,只需 3 分钟,学会创建、管理和共享凭证,让你的自动化流程畅通无阻。
简单来说,凭证就是 n8n 访问外部服务的“钥匙”。
当你想要 n8n 帮你读取 Google Sheets 表格、发送 Slack 消息或调用 OpenAI 接口时,这些服务需要确认“你是谁”以及“你有权限吗”。你将 API Key、用户名密码等机密信息存放在 n8n 的“凭证库”中,工作流运行时会自动取用,既安全又方便。
创建凭证非常直观,就像在手机里添加新的 Wi-Fi 密码一样。

Notion、Telegram 或 HTTP Request)。
导师提示:如果不清楚某个 Key 怎么获取,n8n 的凭证填写界面通常会有一个 "Documentation"(文档)链接,点进去会有手把手的官方指引。
配好了钥匙,怎么用呢?
My Notion Account)。注意:你不需要在节点里重复粘贴 API Key,直接选名字即可。
如果你是在公司团队版(Team/Project)环境中使用 n8n,你可能需要把钥匙分享给同事。
为了让你彻底明白,我们来做一个最通用的练习。我们将使用 n8n 最强大的 HTTP Request 节点配置一个基础认证(Basic Auth)。
我们需要访问一个需要密码的测试 API。我们将创建一个“HTTP Header Auth”凭证,并在工作流中调用它。
请将以下 JSON 代码复制,在你的 n8n 画布上按 Ctrl+V (Mac: Cmd+V) 粘贴:
{
"meta": {
"instanceId": "tutorial-example-01"
},
"nodes": [
{
"parameters": {},
"id": "8d9f6c3b-2a1e-4b5c-9d8e-7f0a1b2c3d4e",
"name": "手动触发",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
460,
300
]
},
{
"parameters": {
"url": "https://httpbin.org/bearer",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"options": {}
},
"id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
"name": "HTTP 请求 (测试凭证)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
680,
300
],
"credentials": {
"httpHeaderAuth": {
"id": "YOUR_CREDENTIAL_ID_HERE",
"name": "请在此处选择你的 Header Auth 凭证"
}
}
}
],
"connections": {
"手动触发": {
"main": [
[
{
"node": "HTTP 请求 (测试凭证)",
"type": "main",
"index": 0
}
]
]
}
}
}Create New(新建)。Authorization,Value 填 Bearer my-secret-token-123。"authenticated": true,说明你成功掌握了凭证的使用![1] 官方文档: https://docs.n8n.io/credentials/
[2] n8n系列教程: https://www.undsky.com/blog/?category=n8n%E6%95%99%E7%A8%8B#