This workflow follows the HTTP Request → Postgres recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"name": "Analyze Data with GPT-4o-mini",
"nodes": [
{
"parameters": {
"functionCode": "const items = $input.all();\nconst avgs = items.map(i => parseFloat(i.json.avg_kwh));\nif (avgs.length === 0) {\n return [{ json: { clients: [], summary: 'Nenhum dado dispon\u00edvel.' } }];\n}\nconst mean = avgs.reduce((a,b)=>a+b,0)/avgs.length;\nconst sd = Math.sqrt(avgs.reduce((s,v)=>s + Math.pow(v-mean,2),0)/avgs.length) || 0;\nconst threshold = 2.5;\nconst result = items.map(i => {\n const avg = parseFloat(i.json.avg_kwh);\n const z = sd === 0 ? 0 : (avg - mean)/sd;\n const status = Math.abs(z) >= threshold ? 'outlier' : 'normal';\n return {\n name: i.json.client_name,\n avg_kwh: Math.round(avg*100)/100,\n status,\n zscore: Math.round(z*100)/100\n };\n});\nreturn [{ json: { clients: result } }];"
},
"id": "0909c7d0-6f8c-4a6a-b5a1-ffafe7bbf228",
"name": "Process JSON",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
656,
144
]
},
{
"parameters": {
"authentication": "headerAuth",
"requestMethod": "POST",
"url": "https://api.openai.com/v1/responses",
"options": {},
"bodyParametersUi": {
"parameter": [
{
"name": "Body",
"value": "\\\"Gere um breve relat\u00f3rio em portugu\u00eas (3 a 6 frases) descrevendo os dados de consumo de energia. Destaque clientes fora do padr\u00e3o, quantos s\u00e3o outliers e inclua uma recomenda\u00e7\u00e3o t\u00e9cnica. Dados: \\\" + JSON.stringify($json.clients),\\n \\\"max_output_tokens\\\": 300\\n}"
}
]
},
"queryParametersUi": {
"parameter": [
{
"name": "executeQuery",
"value": "\"query\": \"WITH last_3_months AS (\\n SELECT r.*\\n FROM readings r\\n JOIN contracts c ON r.contract_id = c.id\\n WHERE c.active = true\\n AND r.read_at >= now() - INTERVAL '3 months'\\n)\\nSELECT\\n cl.name as client_name,\\n AVG(r.kwh) as avg_kwh\\nFROM clients cl\\nJOIN contracts c ON c.client_id = cl.id\\nJOIN last_3_months r ON r.contract_id = c.id\\nGROUP BY cl.name;\""
}
]
}
},
"id": "f1c467c3-45e2-428a-acba-af3a03ea618e",
"name": "Call GPT-4o-mini",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
896,
144
],
"credentials": {
"httpHeaderAuth": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"functionCode": "const clients = $json.clients;\nconst llmText = $json.data?.[0]?.output_text || $json.output || $json.data || '';\nreturn [{ json: { clients, report: llmText } }];"
},
"id": "d04ad193-8ebb-4a1e-a51d-5453351b599b",
"name": "Merge GPT Output",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1152,
144
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "analyze",
"responseMode": "lastNode",
"options": {}
},
"id": "cd034b83-fe85-43bb-a0ee-3c19deb5c623",
"name": "Webhook Analyze1",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
144,
144
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "WITH last_3_months AS (\n SELECT r.*\n FROM readings r\n JOIN contracts c ON r.contract_id = c.id\n WHERE c.active = true\n AND r.read_at >= now() - INTERVAL '3 months'\n)\nSELECT\n cl.name as client_name,\n AVG(r.kwh) as avg_kwh\nFROM clients cl\nJOIN contracts c ON c.client_id = cl.id\nJOIN last_3_months r ON r.contract_id = c.id\nGROUP BY cl.name;",
"additionalFields": {}
},
"id": "72f0b1de-e728-47cd-836d-9163b643e4b4",
"name": "Query Averages1",
"type": "n8n-nodes-base.postgres",
"typeVersion": 1,
"position": [
400,
144
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"options": {}
},
"id": "a5f3d359-38f1-4507-ac44-cf1e56be444a",
"name": "Return JSON1",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
1408,
144
]
}
],
"connections": {
"Webhook Analyze1": {
"main": [
[
{
"node": "Query Averages1",
"type": "main",
"index": 0
}
]
]
},
"Query Averages1": {
"main": [
[
{
"node": "Process JSON",
"type": "main",
"index": 0
}
]
]
},
"Process JSON": {
"main": [
[
{
"node": "Call GPT-4o-mini",
"type": "main",
"index": 0
}
]
]
},
"Call GPT-4o-mini": {
"main": [
[
{
"node": "Merge GPT Output",
"type": "main",
"index": 0
}
]
]
},
"Merge GPT Output": {
"main": [
[
{
"node": "Return JSON1",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1"
},
"versionId": "85890bcb-abbf-4623-b96e-a6b67d12df0e",
"meta": {
"templateCredsSetupCompleted": true
},
"id": "K7jHQlJBIgGmAoWx",
"tags": []
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
httpHeaderAuthpostgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Analyze Data with GPT-4o-mini. Uses httpRequest, postgres. Webhook trigger; 6 nodes.
Source: https://github.com/VictorGonzalez-eng/n8nProject/blob/e87ffdf04b970dc9885cca01d520f03a0e6fa24d/WorkFlows/analyze.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Scraping. Uses httpRequest, postgres, @apify/n8n-nodes-apify, respondToWebhook. Webhook trigger; 61 nodes.
Workflow B — AI Listing Engine. Uses httpRequest, postgres, errorTrigger. Webhook trigger; 47 nodes.
LogSentinel Workflow. Uses postgres, emailSend, httpRequest. Webhook trigger; 44 nodes.
Pawa VAPI Tools v2 (live-schema). Uses postgres, httpRequest. Webhook trigger; 36 nodes.
Fluxo de voluntárias ZendeskXANXBD. Uses functionItem, zendesk, httpRequest, postgres. Webhook trigger; 25 nodes.