// scripts/n8n-api.js const N8N_BASE_URL = "https://n8n32.next-hd.net/api/v1"; const N8N_API_KEY = process.env.N8N_API_KEY; if (!N8N_API_KEY) { throw new Error( "環境変数 N8N_API_KEY が未設定です。NodeSrv/apps/n8n/docs/n8n-guide.md 2章のPublic API Keyを設定してください。" ); } async function request(method, path, body) { const res = await fetch(`${N8N_BASE_URL}${path}`, { method, headers: { "X-N8N-API-KEY": N8N_API_KEY, "Content-Type": "application/json", }, body: body ? JSON.stringify(body) : undefined, }); const text = await res.text(); let json; try { json = text ? JSON.parse(text) : null; } catch { json = text; } return { status: res.status, body: json }; } module.exports = { request };