HTTP Header 的角色
Content-Type: application/json
用來告訴伺服器,我送的內容是 JSON 格式。Authorization: Bearer API_KEY
是身分驗證,沒有這個,伺服器不會理會我的請求。Webhook 的限制
JSON 回傳結構
data.response.output
,有些在 choices[0].message.content
。PowerShell 測試請求失敗
我原本想用
powershell
ConvertTo-Json -Encoding UTF8
結果 PowerShell 根本沒有這個參數,導致失敗。
這說明不同系統(Linux/macOS 的 curl vs Windows PowerShell)在 API 測試上有差異。
Webhook 配置錯誤
NodeOperationError: Webhook node not correctly configured
n8n Function Node 不熟悉
if (data.response && data.response.output) {
reply = data.response.output;
} else if (data.choices && data.choices[0] && data.choices[0].message && data.choices[0].message.content) {
reply = data.choices[0].message.content;
}
雖然今天沒有成功把串接跑通,但我覺得這些「失敗」其實讓我更清楚自己缺什麼:
工具使用差異:
之後要多練習 curl
,因為教學大多用它,跨平台也比較穩定。
JSON Parsing 能力:
觀念比成功更重要:
我現在知道:串 API 不只是「照文件抄」,而是要理解 Request → Response → 資料解析 → 回傳 這一整個流程。
1.改用 Postman 或 curl 測試 Dify API,確保資料能正確送出與接收。
2.學習 n8n Function Node 的基本寫法,把 JSON 解析成乾淨的文字回覆。
3.再次挑戰「Webhook → Dify → Webhook 回傳」這條完整流程。