> ## 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.

# List / search leads

> Returns leads for the authenticated customer. Requires the `public_api:leads:read` scope. Use `sort_by=updated_at&sort_dir=asc` with `cursor` for stable incremental polling.



## OpenAPI

````yaml /openapi.json get /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:
    get:
      tags:
        - Leads
      summary: List / search leads
      description: >-
        Returns leads for the authenticated customer. Requires the
        `public_api:leads:read` scope. Use `sort_by=updated_at&sort_dir=asc`
        with `cursor` for stable incremental polling.
      operationId: listLeads
      parameters:
        - $ref: '#/components/parameters/CustomerId'
        - name: status
          in: query
          schema:
            type: string
          description: Filter by lead status (e.g. active, won, lost, nurture, archived).
        - name: stageId
          in: query
          schema:
            type: string
            format: uuid
          description: Filter by current pipeline stage id.
        - name: search
          in: query
          schema:
            type: string
          description: Free-text match on name / email / phone (phone-format-agnostic).
        - name: created_since
          in: query
          schema:
            type: string
            format: date-time
          description: Only leads created at/after this ISO-8601 timestamp.
        - name: updated_since
          in: query
          schema:
            type: string
            format: date-time
          description: Only leads updated at/after this ISO-8601 timestamp.
        - name: sort_by
          in: query
          schema:
            type: string
            enum:
              - created_at
              - updated_at
              - last_interaction_at
            default: updated_at
        - name: sort_dir
          in: query
          schema:
            type: string
            enum:
              - asc
              - desc
            default: asc
        - name: lead_line
          in: query
          schema:
            type: string
            enum:
              - buyer
              - seller
          description: Filter by the reserved `lead_line` custom field.
        - name: include_custom_fields
          in: query
          schema:
            type: boolean
            default: false
          description: When true, include a `custom_fields` object on each lead.
        - name: cursor
          in: query
          schema:
            type: string
          description: >-
            Opaque keyset cursor from a previous response's `next_cursor`. Only
            valid with the same `sort_by`/`sort_dir`.
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
        - name: offset
          in: query
          schema:
            type: integer
            minimum: 0
            default: 0
          description: >-
            Offset paging (back-compat). Prefer `cursor` for incremental
            polling.
      responses:
        '200':
          description: A page of leads.
          headers:
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LeadListResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '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.
  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
  schemas:
    LeadListResponse:
      type: object
      properties:
        leads:
          type: array
          items:
            $ref: '#/components/schemas/Lead'
        total:
          type: integer
          description: Total matching the filter (ignores cursor/offset).
        limit:
          type: integer
        offset:
          type: integer
        next_cursor:
          type:
            - string
            - 'null'
          description: >-
            Pass as `cursor` to fetch the next page; null when there are no more
            pages.
      required:
        - leads
        - total
        - limit
        - offset
        - next_cursor
    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
    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
    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'
    CustomFieldMap:
      type: object
      description: >-
        Map of custom-field slug to a scalar value (string | number | boolean |
        null).
      additionalProperties:
        type:
          - string
          - number
          - boolean
          - 'null'
  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'
    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.

````