> ## Documentation Index
> Fetch the complete documentation index at: https://dev.gomega.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a single lead

> Creates one lead (or merges into an existing lead by email / phone-last-10). Requires the `public_api:leads:write` scope. Send an `Idempotency-Key` so a retry returns the original result instead of double-creating.



## OpenAPI

````yaml /openapi.json post /api/agents/crm/leads
openapi: 3.1.0
info:
  title: MEGA Public CRM Lead API
  version: 1.0.0
  description: >-
    Server-to-server API to pull leads, push leads (single + bulk), and manage
    lead webhooks for your MEGA CRM. Authenticate with an admin-issued Personal
    Access Token (`Authorization: Bearer mega_...`) plus the `x-customer-id`
    header. These are secret-key endpoints — call them from your backend, never
    from a browser.
servers:
  - url: https://app.gomega.ai
    description: Production
security:
  - bearerAuth: []
paths:
  /api/agents/crm/leads:
    post:
      tags:
        - Leads
      summary: Create a single lead
      description: >-
        Creates one lead (or merges into an existing lead by email /
        phone-last-10). Requires the `public_api:leads:write` scope. Send an
        `Idempotency-Key` so a retry returns the original result instead of
        double-creating.
      operationId: createLead
      parameters:
        - $ref: '#/components/parameters/CustomerId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LeadCreateRequest'
      responses:
        '201':
          description: The created (or merged) lead.
          headers:
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                type: object
                properties:
                  lead:
                    $ref: '#/components/schemas/Lead'
                required:
                  - lead
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  parameters:
    CustomerId:
      name: x-customer-id
      in: header
      required: true
      schema:
        type: string
        format: uuid
      description: >-
        The customer this request acts on. Must match the customer your key is
        locked to.
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
      description: >-
        Client-generated unique key. Replaying the same key returns the original
        stored response instead of creating duplicates. Scoped per customer +
        endpoint; reuse with a different body returns 409.
  schemas:
    LeadCreateRequest:
      type: object
      description: At least one of contact_name, contact_phone, contact_email is required.
      properties:
        contact_name:
          type: string
        contact_phone:
          type: string
        contact_email:
          type: string
          format: email
        source_platform:
          $ref: '#/components/schemas/SourcePlatform'
        source_type:
          $ref: '#/components/schemas/SourceType'
        stage_slug:
          type: string
        custom_fields:
          $ref: '#/components/schemas/CustomFieldMap'
    Lead:
      type: object
      properties:
        id:
          type: string
        customer_id:
          type: string
        contact_name:
          type:
            - string
            - 'null'
        contact_phone:
          type:
            - string
            - 'null'
        contact_email:
          type:
            - string
            - 'null'
        source_platform:
          type: string
        source_type:
          type: string
        status:
          type: string
        score:
          type:
            - integer
            - 'null'
        qualified:
          type:
            - boolean
            - 'null'
        current_stage:
          $ref: '#/components/schemas/Stage'
        owner:
          $ref: '#/components/schemas/Owner'
        last_interaction_at:
          type:
            - string
            - 'null'
          format: date-time
        interaction_count:
          type: integer
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        custom_fields:
          $ref: '#/components/schemas/CustomFieldMap'
      required:
        - id
        - customer_id
        - source_platform
        - source_type
        - status
        - created_at
        - updated_at
    SourcePlatform:
      type: string
      enum:
        - google_ads
        - meta_ads
        - google_organic
        - direct
        - referral
        - hubspot
        - zoho
        - ghl
        - shopify
        - zenmaid
        - lead_docket
        - salesforce
    SourceType:
      type: string
      enum:
        - form
        - phone_call
        - email
        - chat
        - sms
        - manual
        - import
    CustomFieldMap:
      type: object
      description: >-
        Map of custom-field slug to a scalar value (string | number | boolean |
        null).
      additionalProperties:
        type:
          - string
          - number
          - boolean
          - 'null'
    Stage:
      type: object
      nullable: true
      properties:
        id:
          type: string
        slug:
          type: string
        name:
          type: string
        color:
          type:
            - string
            - 'null'
    Owner:
      type:
        - object
        - 'null'
      properties:
        id:
          type: string
        name:
          type: string
        role_name:
          type:
            - string
            - 'null'
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
              enum:
                - authentication_error
                - authorization_error
                - invalid_request_error
                - not_found_error
                - rate_limit_error
                - api_error
            code:
              type: integer
            message:
              type: string
          required:
            - type
            - code
            - message
      required:
        - error
  headers:
    RateLimitLimit:
      description: Request quota for the reported window.
      schema:
        type: integer
    RateLimitRemaining:
      description: Requests remaining in the window.
      schema:
        type: integer
    RateLimitReset:
      description: Seconds until the window fully refills.
      schema:
        type: integer
    RetryAfter:
      description: Seconds to wait before retrying (on 429).
      schema:
        type: integer
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid token / `x-customer-id`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Key lacks the required scope, or is locked to a different customer.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Conflict:
      description: Idempotency-Key reused with a different body, or duplicate resource.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: Rate limit exceeded.
      headers:
        RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        RateLimit-Remaining:
          $ref: '#/components/headers/RateLimitRemaining'
        RateLimit-Reset:
          $ref: '#/components/headers/RateLimitReset'
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Admin-issued Personal Access Token, e.g. `Authorization: Bearer mega_<64
        hex>`. The key carries scopes (`public_api:leads:read`,
        `public_api:leads:write`, `public_api:webhooks:manage`) and is locked to
        one customer.

````