{
  "name": "Plaude 06 - Execution Status Polling",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "plaude-execution-status",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "webhook",
      "name": "Webhook"
    },
    {
      "parameters": {
        "jsCode": "const headers = $input.first().json.headers || {};\nif (headers['x-plaude-api-key'] !== 'bac6629800415b8fd862660f709b7aae7e4fcfd1700418f2acfae4edeb61832a') throw new Error('Unauthorized');\nconst body = $input.first().json.body || $input.first().json;\nif (!body.execution_id) throw new Error('execution_id required');\nreturn [{ json: body }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "id": "validate",
      "name": "Validate"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT * FROM agent_executions WHERE id = '{{ $json.execution_id }}' LIMIT 1",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        440,
        0
      ],
      "id": "fetch",
      "name": "Fetch Execution",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}"
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        660,
        0
      ],
      "id": "respond",
      "name": "Respond"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate": {
      "main": [
        [
          {
            "node": "Fetch Execution",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Execution": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": true
}