{
  "name": "Obatin \u2014 CRUD",
  "nodes": [
    {
      "id": "9c96c00e-7e36-4afb-b1e1-f4b047445525",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "obatin-crud",
        "responseMode": "lastNode",
        "responseData": "all",
        "options": {}
      }
    },
    {
      "id": "08ac367e-ac14-4303-af79-f15d5f6301e8",
      "name": "Validate Token",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2,
      "position": [
        550,
        300
      ],
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT value FROM settings WHERE key = 'token' LIMIT 1",
        "additionalFields": {}
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "3f72238c-27ed-44cf-b486-62b6afe9bbe9",
      "name": "Route Action",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        850,
        300
      ],
      "parameters": {
        "language": "python",
        "code": "import json\nbody = items[0].json['body']\nauth = items[0].json['headers'].get('authorization', '').replace('Bearer ', '')\ndb_token = items[0].json['value']\nif auth != db_token:\n    return [{'json': {'error': 'Unauthorized'}}]\naction = body.get('action', '')\nreturn [{'json': {'action': action, 'body': body, 'authorized': True}}]"
      }
    },
    {
      "id": "e8a7840b-6ee6-496a-9d17-fe8f9c0f5844",
      "name": "Execute SQL",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2,
      "position": [
        1150,
        300
      ],
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ $json.body.query }}",
        "additionalFields": {}
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "28c74724-a1b1-4594-b328-094593a7a46f",
      "name": "Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1450,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBodyType": "json",
        "responseBodyJson": "={{ $json }}"
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Validate Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Token": {
      "main": [
        [
          {
            "node": "Route Action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Action": {
      "main": [
        [
          {
            "node": "Execute SQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute SQL": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": []
}