{
  "name": "Nodbot - Postgres n8n idempotency and event log blueprint",
  "nodes": [
    {
      "parameters": {
        "path": "integration-postgres-n8n",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "6d3b0893-77ee-4eb6-bded-1314b96f61ae",
      "name": "Webhook input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst source = String(src.source ?? 'unknown').trim().toLowerCase();\nconst eventId = String(src.event_id ?? src.id ?? '').trim();\nconst action = String(src.action ?? src.event_type ?? 'process').trim().toLowerCase();\nif (!source || !eventId) throw new Error('Postgres idempotency requires source and event_id');\nconst key = `${source}:${eventId}:${action}`;\nreturn [{ json: {\n  idempotency_key: key,\n  source,\n  event_id: eventId,\n  action,\n  entity_id: String(src.entity_id ?? ''),\n  status: 'received',\n  payload_json: JSON.stringify(src),\n  received_at: new Date().toISOString(),\n  insert_sql: `insert into integration_events (idempotency_key, source, event_id, action, entity_id, status, payload_json, received_at) values ($1,$2,$3,$4,$5,$6,$7,$8) on conflict (idempotency_key) do nothing returning id`,\n  params: [key, source, eventId, action, String(src.entity_id ?? ''), 'received', JSON.stringify(src), new Date().toISOString()]\n}}];"
      },
      "id": "9aa42ecd-f5e5-407e-9e9c-f01e42a94f77",
      "name": "Build idempotency key",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "40b7a22c-8094-4630-a84a-e68a9170496b",
      "name": "Insert event log",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "b3b3d11c-349a-4965-a89f-a79c70c42098",
      "name": "Process only new event",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "64ce9e3c-6883-453b-84ce-e6c466f774c9",
      "name": "Business action",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "e23694a1-4ece-46a5-acd4-a2f9ed6d3008",
      "name": "Mark processed",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "Webhook input": {
      "main": [
        [
          {
            "node": "Build idempotency key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build idempotency key": {
      "main": [
        [
          {
            "node": "Insert event log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert event log": {
      "main": [
        [
          {
            "node": "Process only new event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process only new event": {
      "main": [
        [
          {
            "node": "Business action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Business action": {
      "main": [
        [
          {
            "node": "Mark processed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "integration",
    "production"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "c64099cc-3d88-466b-b172-d61b941ada03",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}