內容簡介
HTTP Request Node 是 n8n 中強大的功能節點,允許用戶透過 HTTP 請求與外部 API 進行互動。
本文將介紹該節點的應用場景、範例工作流程,以及如何最佳化其使用。
範例場景
假設您需要自動獲取天氣資料,並將其記錄到 Google Sheets 中。HTTP Request Node 可用於向天氣 API 發送請求並獲取天氣資訊。
Workflow 範例
範例說明
此工作流程包含兩個節點:
- HTTP Request Node:向 Weather API 發送 GET 請求,並獲取當前天氣資訊。
- Set Node:將天氣資訊存入變數,供後續處理或儲存。
執行前、後差異
執行前:工作流程未開始,未有任何數據記錄。
[
{
"location": {
"name": "Taipei",
"region": "T'ai-pei",
"country": "Taiwan",
"lat": 25.0392,
"lon": 121.525,
"tz_id": "Asia/Taipei",
"localtime_epoch": 1735520021,
"localtime": "2024-12-30 08:53"
},
"current": {
"last_updated_epoch": 1735519500,
"last_updated": "2024-12-30 08:45",
"temp_c": 18.2,
"temp_f": 64.8,
"is_day": 1,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
"code": 1003
},
"wind_mph": 2.9,
"wind_kph": 4.7,
"wind_degree": 171,
"wind_dir": "S",
"pressure_mb": 1023,
"pressure_in": 30.21,
"precip_mm": 0,
"precip_in": 0,
"humidity": 77,
"cloud": 75,
"feelslike_c": 18.2,
"feelslike_f": 64.8,
"windchill_c": 15.5,
"windchill_f": 59.8,
"heatindex_c": 15.5,
"heatindex_f": 59.8,
"dewpoint_c": 9.5,
"dewpoint_f": 49.2,
"vis_km": 10,
"vis_miles": 6,
"uv": 0.6,
"gust_mph": 4.1,
"gust_kph": 6.6
}
}
]
執行後:從 Weather API 獲取的天氣資料會存儲在工作流程的輸出中,例如天氣狀態與溫度。
[
{
"Country": "Taiwan",
"City": "Taipei",
"Weather": "Partly cloudy",
"Temperature": "18.2"
}
]
小技巧
- 請確保您的 API 密鑰有效,並遵守 API 的使用限制。
- 使用 Set Node 可方便地格式化數據,以供其他節點使用。
- 使用 Debug Console 查看請求和回應,確保工作流程正確執行。
參考連結
- https://docs.n8n.io/nodes/n8n-nodes-base.httpRequest/
- https://weatherapi.com/