{
  "openapi": "3.0.3",
  "info": {
    "title": "Adwix Atlas API",
    "version": "1.0.0",
    "description": "Public REST API for Adwix Atlas — leads and customers. Authenticate with a workspace API key (Settings → Integrations → API Keys): `Authorization: Bearer aa_live_…`. Rate limit: 120 requests/minute per key. Docs: https://adwixatlas.com/platform/rest-api"
  },
  "servers": [{ "url": "https://adwixatlas.com/api/v1" }],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/leads": {
      "get": {
        "summary": "List leads",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0, "default": 0 } },
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["new", "contacted", "qualified", "proposal_sent", "negotiating", "confirmed", "lost", "cancelled"] } }
        ],
        "responses": {
          "200": {
            "description": "Leads, newest first.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Lead" } }, "has_more": { "type": "boolean" } } } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "summary": "Create a lead",
        "description": "At least one of name, phone or email is required. Accepts the same field aliases as the lead webhook; unmapped keys are preserved in the lead's notes. source defaults to \"api\" when omitted. Creating a lead fires the workspace's automations and (with attribution ids) a Meta CAPI Lead event.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LeadCreate" } } }
        },
        "responses": {
          "201": { "description": "Created.", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Lead" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "413": { "$ref": "#/components/responses/TooLarge" },
          "422": { "$ref": "#/components/responses/Invalid" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/leads/{id}": {
      "get": {
        "summary": "Fetch one lead",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The lead.", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Lead" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/customers": {
      "get": {
        "summary": "List customers",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0, "default": 0 } },
          { "name": "search", "in": "query", "schema": { "type": "string" }, "description": "Case-insensitive match on name, phone or email." }
        ],
        "responses": {
          "200": {
            "description": "Customers, newest first.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Customer" } }, "has_more": { "type": "boolean" } } } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "summary": "Create a customer",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CustomerCreate" } } }
        },
        "responses": {
          "201": { "description": "Created.", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Customer" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "413": { "$ref": "#/components/responses/TooLarge" },
          "422": { "$ref": "#/components/responses/Invalid" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/customers/{id}": {
      "get": {
        "summary": "Fetch one customer",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The customer.", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Customer" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "Workspace API key: aa_live_…" }
    },
    "responses": {
      "Unauthorized": { "description": "Missing, invalid or revoked API key.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound": { "description": "Not found (including ids from another workspace).", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Invalid": { "description": "Validation failed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "TooLarge": { "description": "Body exceeded 100 KB.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "RateLimited": { "description": "Over 120 requests/minute for this key. Honour Retry-After.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    },
    "schemas": {
      "Error": { "type": "object", "properties": { "error": { "type": "string" } } },
      "Lead": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "phone": { "type": "string" },
          "email": { "type": "string" },
          "destination": { "type": "string" },
          "budget": { "type": "number" },
          "pax": { "type": "integer" },
          "travel_date": { "type": "string" },
          "status": { "type": "string", "enum": ["new", "contacted", "qualified", "proposal_sent", "negotiating", "confirmed", "lost", "cancelled"] },
          "source": { "type": "string" },
          "score": { "type": "integer" },
          "notes": { "type": "string" },
          "follow_up_date": { "type": "string", "nullable": true },
          "tags": { "type": "array", "items": { "type": "string" } },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "LeadCreate": {
        "type": "object",
        "description": "At least one of name, phone or email is required. Optional attribution: fbclid, fbc, fbp, source_url.",
        "properties": {
          "name": { "type": "string" },
          "phone": { "type": "string" },
          "email": { "type": "string" },
          "destination": { "type": "string" },
          "budget": { "type": "number" },
          "pax": { "type": "integer" },
          "travel_date": { "type": "string" },
          "status": { "type": "string" },
          "source": { "type": "string" },
          "notes": { "type": "string" }
        }
      },
      "Customer": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "phone": { "type": "string" },
          "email": { "type": "string" },
          "address": { "type": "string" },
          "state": { "type": "string" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "total_bookings": { "type": "integer", "readOnly": true },
          "total_spend": { "type": "number", "readOnly": true },
          "last_travel_date": { "type": "string", "nullable": true, "readOnly": true },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "CustomerCreate": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": { "type": "string" },
          "phone": { "type": "string" },
          "email": { "type": "string" },
          "address": { "type": "string" },
          "state": { "type": "string" },
          "tags": { "type": "array", "items": { "type": "string" }, "maxItems": 20 }
        }
      }
    }
  }
}
