{
  "info": {
    "name": "CapData API Collection",
    "description": "Complete API collection for CapData - Intelligent Data Extraction Platform",
    "version": "1.0.0",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://capdata.es",
      "type": "string"
    },
    {
      "key": "api_key",
      "value": "your_api_key_here",
      "type": "string"
    },
    {
      "key": "employee_token",
      "value": "your_employee_token_here",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "Health Check",
      "item": [
        {
          "name": "Ping",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/health/ping",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "health",
                "ping"
              ]
            }
          }
        },
        {
          "name": "Database Health",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/health/database",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "health",
                "database"
              ]
            }
          }
        },
        {
          "name": "Application Status",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/health/status",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "health",
                "status"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Main API",
      "item": [
        {
          "name": "Extract Flight Data",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"html\": \"<html>Flight booking HTML content</html>\", \"context\": {\"is_vueling\": false}, \"include_avsis\": false}"
            },
            "url": {
              "raw": "{{base_url}}/api/extract",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "extract"
              ]
            }
          }
        },
        {
          "name": "Send to Clientify",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"clientify_token\": \"your_clientify_token\", \"flight_data\": {\"codigo_reserva\": \"ABC123\", \"nombre_pasajero\": \"John Doe\"}}"
            },
            "url": {
              "raw": "{{base_url}}/api/sendToClientify",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "sendToClientify"
              ]
            }
          }
        },
        {
          "name": "Update Reservation",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"flight_data\": {\"codigo_reserva\": \"ABC123\", \"nombre_pasajero\": \"John Doe Updated\"}}"
            },
            "url": {
              "raw": "{{base_url}}/api/update_reservation",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "update_reservation"
              ]
            }
          }
        },
        {
          "name": "Get Form Selectors",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"domain\": \"example.com\", \"html\": \"<html>Website HTML content</html>\", \"force_analysis\": false}"
            },
            "url": {
              "raw": "{{base_url}}/api/form-selectors",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "form-selectors"
              ]
            }
          }
        },
        {
          "name": "Get Fields Definition",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/api/get-fields-definition",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "get-fields-definition"
              ]
            }
          }
        },
        {
          "name": "List Contacts",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/contacts?page=1&per_page=50&search=&entity_type=&role=",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "contacts"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "per_page",
                  "value": "50"
                },
                {
                  "key": "search",
                  "value": ""
                },
                {
                  "key": "entity_type",
                  "value": ""
                },
                {
                  "key": "role",
                  "value": ""
                }
              ]
            }
          }
        },
        {
          "name": "Get My Integrations",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/me/integrations",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "me",
                "integrations"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Management API",
      "item": [
        {
          "name": "Create Agency",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"New Agency\", \"consumes_owner_tokens\": true, \"contact_person\": \"Contact Person\", \"phone_number\": \"+34123456789\"}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agencies",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agencies"
              ]
            },
            "description": "Create a new agency. Only 'name' is required. Email and password are optional - if not provided, agency is created as organizational container without login credentials."
          }
        },
        {
          "name": "Create Agent",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"New Agent\"}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agents",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agents"
              ]
            },
            "description": "Create a new agent for the owner. Only 'name' is required. Username is auto-generated if not provided. Username and password are optional - if not provided, agent has only API token access."
          }
        },
        {
          "name": "Create Agency Agent",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"Agency Agent\"}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agencies/{{agency_id}}/agents",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agencies",
                "1",
                "agents"
              ]
            },
            "description": "Create a new agent for an agency. Only 'name' is required. Username is auto-generated if not provided. Username and password are optional - if not provided, agent has only API token access."
          }
        },
        {
          "name": "Update Agent Status",
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"is_active\": false}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agents/{{agent_id}}/status",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agents",
                "1",
                "status"
              ]
            },
            "description": "Activate or deactivate an agent"
          }
        },
        {
          "name": "Regenerate Agent Token",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/management/agents/{{agent_id}}/regenerate-token",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agents",
                "1",
                "regenerate-token"
              ]
            },
            "description": "Regenerate an agent's API token. The old token becomes invalid."
          }
        },
        {
          "name": "Update Agent (Owner)",
          "request": {
            "method": "PUT",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"Updated Agent Name\", \"is_active\": false, \"token_regenerate\": true}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agents/{{agent_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agents",
                "{{agent_id}}"
              ]
            },
            "description": "Comprehensive update for an agent. Can update name, is_active, and regenerate token."
          }
        },
        {
          "name": "Update Agency Agent",
          "request": {
            "method": "PUT",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"Updated Agency Agent\", \"is_active\": true, \"token_regenerate\": false}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agencies/{{agency_id}}/agents/{{agent_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agencies",
                "{{agency_id}}",
                "agents",
                "{{agent_id}}"
              ]
            },
            "description": "Comprehensive update for an agency's agent. Can update name, is_active, and regenerate token."
          }
        },
        {
          "name": "Update Agency Status",
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"is_active\": false}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agencies/{{agency_id}}/status",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agencies",
                "{{agency_id}}",
                "status"
              ]
            },
            "description": "Activate or deactivate an agency. When deactivating, all agents are automatically deactivated (CASCADE)."
          }
        },
        {
          "name": "Update Agency",
          "request": {
            "method": "PUT",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"Updated Agency Name\", \"is_active\": true, \"consumes_owner_tokens\": false, \"contact_person\": \"John Smith\", \"phone_number\": \"+34123456789\", \"address_line1\": \"Calle Principal 123\", \"city\": \"Madrid\", \"postal_code\": \"28001\", \"country\": \"Spain\", \"notes\": \"Updated notes\"}"
            },
            "url": {
              "raw": "{{base_url}}/api/management/agencies/{{agency_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "agencies",
                "{{agency_id}}"
              ]
            },
            "description": "Comprehensive update for an agency. Can update all fields including name, status, contact info, and address. When is_active changes to false, all agents are automatically deactivated."
          }
        }
      ]
    },
    {
      "name": "Chat API",
      "item": [
        {
          "name": "List Chat Folders",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/chat/folders",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "chat",
                "folders"
              ]
            }
          }
        },
        {
          "name": "Create Chat Folder",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"name\": \"New Folder\"}"
            },
            "url": {
              "raw": "{{base_url}}/api/chat/folders",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "chat",
                "folders"
              ]
            }
          }
        },
        {
          "name": "List Conversations",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/chat/conversations",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "chat",
                "conversations"
              ]
            }
          }
        },
        {
          "name": "Create Conversation",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"title\": \"New Conversation\", \"folder_id\": 1}"
            },
            "url": {
              "raw": "{{base_url}}/api/chat/conversations",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "chat",
                "conversations"
              ]
            }
          }
        },
        {
          "name": "Send Message",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"content\": \"Hello, how can I help you?\", \"conversation_id\": 1}"
            },
            "url": {
              "raw": "{{base_url}}/api/chat/conversations/1/messages",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "chat",
                "conversations",
                "1",
                "messages"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Integrations API",
      "item": [
        {
          "name": "List Integrations",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/v1/integrations",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "v1",
                "integrations"
              ]
            }
          }
        },
        {
          "name": "Get Integration",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/v1/integrations/visagov",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "v1",
                "integrations",
                "visagov"
              ]
            }
          }
        },
        {
          "name": "Update Integration",
          "request": {
            "method": "PUT",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "X-API-Key",
                "value": "{{api_key}}"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\"enabled\": true, \"settings\": {\"api_key\": \"your_integration_api_key\"}}"
            },
            "url": {
              "raw": "{{base_url}}/api/v1/integrations/visagov",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "v1",
                "integrations",
                "visagov"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Token Consumption API",
      "description": "API endpoints for querying token consumption logs for pay-per-use billing. Requires Owner API Key (X-Owner-API-Key) for authentication.",
      "item": [
        {
          "name": "Get Consumption Logs",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}",
                "description": "Owner API Key for authentication"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/management/token-consumption?start_date=2025-10-01&end_date=2025-10-31&limit=100&offset=0",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "token-consumption"
              ],
              "query": [
                {
                  "key": "start_date",
                  "value": "2025-10-01",
                  "description": "Start date in YYYY-MM-DD format (optional)"
                },
                {
                  "key": "end_date",
                  "value": "2025-10-31",
                  "description": "End date in YYYY-MM-DD format (optional)"
                },
                {
                  "key": "agent_id",
                  "value": "",
                  "description": "Filter by agent ID (optional)",
                  "disabled": true
                },
                {
                  "key": "agency_id",
                  "value": "",
                  "description": "Filter by agency ID (optional)",
                  "disabled": true
                },
                {
                  "key": "action_type",
                  "value": "",
                  "description": "Filter by action type, e.g. 'api_extract' (optional)",
                  "disabled": true
                },
                {
                  "key": "limit",
                  "value": "100",
                  "description": "Number of results (default: 100, max: 1000)"
                },
                {
                  "key": "offset",
                  "value": "0",
                  "description": "Pagination offset (default: 0)"
                },
                {
                  "key": "include_zero",
                  "value": "false",
                  "description": "Include operations with 0 tokens (default: false)",
                  "disabled": true
                }
              ]
            },
            "description": "Query token consumption logs with optional filters. Returns both detailed logs and breakdown totals (agencies/agents) in a single response. Perfect for billing and auditing."
          },
          "response": []
        },
        {
          "name": "Get Consumption Summary",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}",
                "description": "Owner API Key for authentication"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/management/token-consumption/summary?start_date=2025-10-01&end_date=2025-10-31",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "token-consumption",
                "summary"
              ],
              "query": [
                {
                  "key": "start_date",
                  "value": "2025-10-01",
                  "description": "Start date in YYYY-MM-DD format (optional)"
                },
                {
                  "key": "end_date",
                  "value": "2025-10-31",
                  "description": "End date in YYYY-MM-DD format (optional)"
                }
              ]
            },
            "description": "Get aggregated summary of token consumption by action type. Useful for understanding which operations consume the most tokens."
          },
          "response": []
        },
        {
          "name": "Get Descendants Breakdown",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}",
                "description": "Owner API Key for authentication"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/management/token-consumption/descendants?start_date=2025-10-01&end_date=2025-10-31",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "token-consumption",
                "descendants"
              ],
              "query": [
                {
                  "key": "start_date",
                  "value": "2025-10-01",
                  "description": "Start date in YYYY-MM-DD format (optional)"
                },
                {
                  "key": "end_date",
                  "value": "2025-10-31",
                  "description": "End date in YYYY-MM-DD format (optional)"
                }
              ]
            },
            "description": "Get token consumption breakdown by agencies and agents. Shows total tokens consumed by each descendant entity with operation counts. Perfect for understanding which agencies/agents are using the most tokens."
          },
          "response": []
        },
        {
          "name": "Export to Excel",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}",
                "description": "Owner API Key for authentication"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/management/token-consumption/export?start_date=2025-10-01&end_date=2025-10-31",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "token-consumption",
                "export"
              ],
              "query": [
                {
                  "key": "start_date",
                  "value": "2025-10-01",
                  "description": "Start date in YYYY-MM-DD format (optional)"
                },
                {
                  "key": "end_date",
                  "value": "2025-10-31",
                  "description": "End date in YYYY-MM-DD format (optional)"
                },
                {
                  "key": "agent_id",
                  "value": "",
                  "description": "Filter by agent ID (optional)",
                  "disabled": true
                },
                {
                  "key": "agency_id",
                  "value": "",
                  "description": "Filter by agency ID (optional)",
                  "disabled": true
                },
                {
                  "key": "action_type",
                  "value": "",
                  "description": "Filter by action type (optional)",
                  "disabled": true
                }
              ]
            },
            "description": "Export token consumption logs to Excel file (.xlsx). Returns a downloadable file with all consumption data including performer details, timestamps, and token counts. Perfect for offline analysis and record-keeping."
          },
          "response": []
        },
        {
          "name": "Integrity Check",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "X-Owner-API-Key",
                "value": "{{api_key}}",
                "description": "Owner API Key for authentication"
              }
            ],
            "url": {
              "raw": "{{base_url}}/api/management/token-consumption/integrity-check",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "management",
                "token-consumption",
                "integrity-check"
              ]
            },
            "description": "Verify token consumption integrity by comparing current balance with recorded purchases and consumption. Helps detect any discrepancies in billing and ensures accurate token accounting."
          },
          "response": []
        }
      ]
    }
  ]
}