{
  "openapi": "3.1.0",
  "info": {
    "title": "Xpertixe Lead API",
    "description": "Public lead capture endpoint used by Xpertixe website forms (growth audit, contact, let's connect). Submissions are forwarded server-side to the CRM; no API key is required from agents or browsers.",
    "version": "1.0.0",
    "contact": {
      "name": "Xpertixe",
      "url": "https://xpertixe.com/contact",
      "email": "hello@xpertixe.com"
    }
  },
  "servers": [
    {
      "url": "https://xpertixe.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/ghl/lead": {
      "post": {
        "operationId": "submitLead",
        "summary": "Submit a website lead",
        "description": "Creates or updates a contact from a website form submission. Name, email, and phone are required. Source must be one of the known form origins.",
        "tags": ["Leads"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeadInput"
              },
              "examples": {
                "growthAudit": {
                  "summary": "Growth audit request",
                  "value": {
                    "source": "growth-audit",
                    "name": "Alex Morgan",
                    "email": "alex@example.com",
                    "phone": "+1-555-0100",
                    "company": "Acme Co",
                    "website": "https://example.com",
                    "service": "SEO Services",
                    "message": "Free growth audit request",
                    "pagePath": "/"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadSuccess"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadError"
                }
              }
            }
          },
          "503": {
            "description": "CRM not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "LeadInput": {
        "type": "object",
        "required": ["source", "name", "email", "phone"],
        "properties": {
          "source": {
            "type": "string",
            "enum": ["growth-audit", "homepage", "contact", "lets-connect"],
            "description": "Which website form originated the lead"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "description": "Full name"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string",
            "minLength": 1,
            "description": "Phone number (required)"
          },
          "company": {
            "type": "string"
          },
          "website": {
            "type": "string",
            "description": "Business website; bare domains are normalized to https://"
          },
          "address": {
            "type": "string"
          },
          "service": {
            "type": "string",
            "description": "Service interest label"
          },
          "budget": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "pagePath": {
            "type": "string",
            "description": "Page path where the form was submitted (for CRM notes)"
          }
        },
        "additionalProperties": false
      },
      "LeadSuccess": {
        "type": "object",
        "required": ["ok"],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          }
        }
      },
      "LeadError": {
        "type": "object",
        "required": ["ok", "error"],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}
