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

# Bulk create / merge leads

> Import up to 500 leads in one request. Requires the `public_api:leads:write` scope. Uploaded leads are inert (no downstream automation). Use `dry_run: true` to preview, `on_duplicate` to control merge behavior, and `Idempotency-Key` to make retries safe. Subject to a stricter per-minute rate limit than the other endpoints.



## OpenAPI

````yaml /openapi.json post /api/agents/crm/leads/bulk
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/bulk:
    post:
      tags:
        - Leads
      summary: Bulk create / merge leads
      description: >-
        Import up to 500 leads in one request. Requires the
        `public_api:leads:write` scope. Uploaded leads are inert (no downstream
        automation). Use `dry_run: true` to preview, `on_duplicate` to control
        merge behavior, and `Idempotency-Key` to make retries safe. Subject to a
        stricter per-minute rate limit than the other endpoints.
      operationId: bulkImportLeads
      parameters:
        - $ref: '#/components/parameters/CustomerId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BulkImportRequest'
      responses:
        '200':
          description: Per-row import results + summary.
          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/BulkImportResponse'
        '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:
    BulkImportRequest:
      type: object
      properties:
        leads:
          type: array
          minItems: 1
          maxItems: 500
          items:
            $ref: '#/components/schemas/BulkLeadRow'
        on_duplicate:
          type: string
          enum:
            - update
            - skip
          default: update
        dry_run:
          type: boolean
          default: false
      required:
        - leads
    BulkImportResponse:
      type: object
      properties:
        dry_run:
          type: boolean
        summary:
          type: object
          properties:
            total:
              type: integer
            created:
              type: integer
            updated:
              type: integer
            skipped:
              type: integer
            failed:
              type: integer
          required:
            - total
            - created
            - updated
            - skipped
            - failed
        results:
          type: array
          items:
            $ref: '#/components/schemas/BulkRowResult'
        unknown_custom_fields:
          type: array
          items:
            type: string
          description: >-
            Custom-field slugs that did not match any definition and were
            ignored.
      required:
        - dry_run
        - summary
        - results
        - unknown_custom_fields
    BulkLeadRow:
      type: object
      description: At least one of contact_name, contact_phone, contact_email is required.
      properties:
        row_ref:
          type: string
          description: Your correlation id, echoed back in the per-row result.
        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
        owner_id:
          type: string
          format: uuid
          description: Must be one of the customer's team members.
        lead_line:
          type: string
          enum:
            - buyer
            - seller
        custom_fields:
          $ref: '#/components/schemas/CustomFieldMap'
    BulkRowResult:
      type: object
      properties:
        row_ref:
          type:
            - string
            - 'null'
        status:
          type: string
          enum:
            - created
            - updated
            - skipped
            - failed
        lead_id:
          type:
            - string
            - 'null'
        matched_by:
          type:
            - string
            - 'null'
          enum:
            - email
            - phone
            - null
        errors:
          type:
            - array
            - 'null'
          items:
            type: string
        ignored_custom_fields:
          type: array
          items:
            type: string
      required:
        - row_ref
        - status
        - lead_id
        - matched_by
        - errors
    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
    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'
  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.

````