{
  "name": "Get - KB",
  "nodes": [
    {
      "parameters": {
        "operation": "select",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "enlaight_knowledge_bases",
          "mode": "list",
          "cachedResultName": "enlaight_knowledge_bases"
        },
        "limit": 1,
        "where": {
          "values": [
            {
              "column": "hash_id",
              "value": "={{ $('Webhook').item.json.body.hash_id }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -800,
        -140
      ],
      "id": "9a83402d-b042-44ba-a922-42cc523a21d1",
      "name": "enlaight_knowledge_bases",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "path": "kb/get/",
        "authentication": "headerAuth",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1940,
        100
      ],
      "id": "e648bc30-b573-4f4d-aaf3-a2276e9974e8",
      "name": "Webhook",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"status\": \"success\",\n  \"name\": \"{{ $json.name }}\",\n  \"description\": \"{{ $json.description }}\",\n  \"hash_id\": \"{{ $json.hash_id }}\",\n  \"created_at\": \"{{ $json.created_at }}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.2,
      "position": [
        -460,
        -240
      ],
      "id": "b7bdc2c2-e14c-424b-aa7b-56519dc92c24",
      "name": "Respond to Webhook2"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\n  \"status\": \"error\",\n  \"reason\": \"Error while editing knowledge base\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.2,
      "position": [
        -460,
        -40
      ],
      "id": "136d0a03-8760-464e-90dc-1c5267a916ea",
      "name": "respond_error_while_creating"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "e928902e-f8b6-4e16-94c0-f9e7cdb3d4e2",
              "leftValue": "={{ $json.body.hash_id }}",
              "rightValue": 0,
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -1660,
        100
      ],
      "id": "dbc1c879-db24-455d-9f1a-675d46f0c1cc",
      "name": "check_payload1"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\n  \"status\": \"error\",\n  \"reason\": \"invalid input\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.2,
      "position": [
        -1340,
        220
      ],
      "id": "bacd512b-5e03-4d0f-932d-58573251fe0b",
      "name": "respond_error_invalid_response1"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select count(*) from enlaight_knowledge_bases where hash_id = '{{ $('Webhook').item.json.body.hash_id }}';",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -1340,
        -20
      ],
      "id": "9cea449a-68a3-4828-8623-ef34058de143",
      "name": "enlaight_knowledge_bases3",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "e928902e-f8b6-4e16-94c0-f9e7cdb3d4e2",
              "leftValue": "={{ Number($json.count) }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -1120,
        -20
      ],
      "id": "c934d826-f57f-4c48-b832-4a2c62b93f33",
      "name": "If1"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\n  \"status\": \"error\",\n  \"reason\": \"knowledge base does not exist\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.2,
      "position": [
        -800,
        100
      ],
      "id": "8a744cdc-1844-46d8-bf81-f2e3ac4ee6a3",
      "name": "respond_error_kb_does_not_exists"
    }
  ],
  "connections": {
    "enlaight_knowledge_bases": {
      "main": [
        [
          {
            "node": "Respond to Webhook2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "respond_error_while_creating",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "check_payload1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check_payload1": {
      "main": [
        [
          {
            "node": "enlaight_knowledge_bases3",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "respond_error_invalid_response1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "enlaight_knowledge_bases3": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "enlaight_knowledge_bases",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "respond_error_kb_does_not_exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": null
}