{
  "id": "4lXQVvpcLF0mnwGj",
  "name": "Gemini File Search - Create Store (Webhook)",
  "description": "Creates a new Gemini File Search Store (corpus). Webhook endpoint: POST /kb-create-store with apiKey and displayName in body.",
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "kb-create-store",
        "responseMode": "lastNode",
        "options": {
          "responseData": "firstEntryJson"
        }
      },
      "id": "Webhook",
      "name": "Webhook /kb-create-store",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        280,
        300
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const { apiKey, displayName } = $json;\nif (!apiKey) return [{ json: { status: 'ERROR', error: 'apiKey required' } }];\nif (!displayName) return [{ json: { status: 'ERROR', error: 'displayName required' } }];\nreturn [{ json: { apiKey, displayName } }];"
      },
      "id": "Validate",
      "name": "Validate Input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://generativelanguage.googleapis.com/v1beta/corpora?key={{$json.apiKey}}",
        "responseFormat": "json",
        "jsonParameters": true,
        "options": {},
        "body": "={ \"displayName\": $json.displayName }"
      },
      "id": "Http Request",
      "name": "Create Store",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        760,
        300
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const res = $json;\nif (res.statusCode && res.statusCode >= 400) {\n  return [{ json: { status: 'ERROR', error: `Gemini returned ${res.statusCode}`, body: res.body || res } }];\n}\nreturn [{ json: { status: 'SUCCESS', store: res.body || res } }];"
      },
      "id": "Return",
      "name": "Format Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1000,
        300
      ]
    }
  ],
  "connections": {
    "Webhook /kb-create-store": {
      "main": [
        [
          {
            "node": "Validate Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Input": {
      "main": [
        [
          {
            "node": "Create Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Store": {
      "main": [
        [
          {
            "node": "Format Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "meta": null
}