{
  "openapi": "3.0.3",
  "info": {
    "title": "ClawCRM API",
    "description": "AI-Native CRM API — manage leads, campaigns, follow-ups, analytics, and more.",
    "version": "1.0.0",
    "contact": { "name": "Protosome Inc", "url": "https://clawcrm.ai" }
  },
  "servers": [{ "url": "https://clawcrm.ai", "description": "Production" }],
  "security": [{ "AdminToken": [] }],
  "components": {
    "securitySchemes": {
      "AdminToken": {
        "type": "apiKey",
        "in": "header",
        "name": "x-admin-token"
      }
    }
  },
  "paths": {
    "/api/openclaw/leads": {
      "get": {
        "summary": "List leads",
        "description": "Returns all leads with scores, quiz answers, and segments.",
        "responses": { "200": { "description": "Array of leads" } }
      },
      "post": {
        "summary": "Create lead",
        "description": "Create a new lead.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["firstName", "lastName", "email"],
                "properties": {
                  "firstName": { "type": "string" },
                  "lastName": { "type": "string" },
                  "email": { "type": "string" },
                  "clinicName": { "type": "string" },
                  "practiceType": { "type": "string" },
                  "phone": { "type": "string" },
                  "customFields": { "type": "object" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Lead created" } }
      },
      "put": {
        "summary": "Update lead",
        "description": "Update an existing lead.",
        "responses": { "200": { "description": "Lead updated" } }
      }
    },
    "/api/openclaw/analytics": {
      "get": {
        "summary": "Get analytics",
        "description": "Pipeline metrics, conversion rates, engagement stats.",
        "responses": { "200": { "description": "Analytics object" } }
      }
    },
    "/api/openclaw/campaigns": {
      "get": {
        "summary": "List campaigns",
        "description": "List all campaign sequences.",
        "responses": { "200": { "description": "Array of campaigns" } }
      },
      "post": {
        "summary": "Create campaign",
        "description": "Create a new campaign sequence.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "trigger_event", "steps"],
                "properties": {
                  "name": { "type": "string" },
                  "trigger_event": { "type": "string" },
                  "steps": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "channel": { "type": "string" },
                        "delay_minutes": { "type": "integer" },
                        "subject": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Campaign created" } }
      }
    },
    "/api/openclaw/touchpoints": {
      "get": {
        "summary": "List touchpoints",
        "description": "Lead activity and interaction history.",
        "responses": { "200": { "description": "Array of touchpoints" } }
      },
      "post": {
        "summary": "Log touchpoint",
        "description": "Log a new interaction with a lead.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["lead_id", "channel", "action"],
                "properties": {
                  "lead_id": { "type": "string" },
                  "channel": { "type": "string" },
                  "action": { "type": "string" },
                  "notes": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Touchpoint logged" } }
      }
    },
    "/api/openclaw/followups": {
      "get": {
        "summary": "List follow-ups",
        "description": "Email templates and actionable follow-up leads.",
        "responses": { "200": { "description": "Follow-up data" } }
      },
      "post": {
        "summary": "Send follow-up",
        "description": "Send a follow-up email to a lead.",
        "responses": { "200": { "description": "Follow-up sent" } }
      }
    },
    "/api/openclaw/quiz": {
      "get": {
        "summary": "Get quiz config",
        "description": "Quiz configuration with 6 modules.",
        "responses": { "200": { "description": "Quiz config" } }
      },
      "patch": {
        "summary": "Update quiz",
        "description": "Modify quiz questions.",
        "responses": { "200": { "description": "Quiz updated" } }
      }
    },
    "/api/openclaw/playbooks": {
      "get": {
        "summary": "List playbooks",
        "description": "SDR workflows and best practices.",
        "responses": { "200": { "description": "Array of playbooks" } }
      },
      "post": {
        "summary": "Get recommendation",
        "description": "Get AI recommendation for a sales scenario.",
        "responses": { "200": { "description": "Recommendation" } }
      }
    },
    "/api/openclaw/integrations": {
      "get": {
        "summary": "List integrations",
        "description": "List connected providers.",
        "responses": { "200": { "description": "Array of integrations" } }
      },
      "post": {
        "summary": "Add integration",
        "description": "Connect a new provider.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["type", "provider", "name"],
                "properties": {
                  "type": { "type": "string" },
                  "provider": { "type": "string" },
                  "name": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Integration added" } }
      }
    },
    "/api/openclaw/health": {
      "get": {
        "summary": "Health check",
        "description": "Debug and health check endpoint.",
        "responses": { "200": { "description": "Health status" } }
      }
    }
  }
}
