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

# Create or update a lead

> If the agent already has a WhatsApp or Lead Ads lead with that phone number, in any of its forms, updates it and returns 200; otherwise creates it and returns 201. A voice or web chat lead with the same number does not count. The name changes only if you send it, and variables are merged with the existing ones.



## OpenAPI

````yaml /openapi.yaml post /leads
openapi: 3.1.0
info:
  title: NewLead API
  version: 1.0.0
  description: >-
    The NewLead public API. Each API key belongs to one subaccount and can read
    and change only that subaccount's data. Errors, pagination, idempotency and
    rate limits are documented at https://docs.newlead.ai.
servers:
  - url: https://rest.newlead.ai/v1
security:
  - BearerAuth: []
  - ApiKeyHeader: []
tags:
  - name: Specification
    description: This document.
paths:
  /leads:
    post:
      tags:
        - Leads
      summary: Create or update a lead
      description: >-
        If the agent already has a WhatsApp or Lead Ads lead with that phone
        number, in any of its forms, updates it and returns 200; otherwise
        creates it and returns 201. A voice or web chat lead with the same
        number does not count. The name changes only if you send it, and
        variables are merged with the existing ones.
      operationId: createLead
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LeadCreateRequest'
      responses:
        '200':
          description: 'Already existed: the updated lead.'
          headers:
            X-Request-ID:
              $ref: '#/components/headers/X-Request-ID'
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimit-Limit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimit-Remaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimit-Reset'
            Idempotent-Replayed:
              $ref: '#/components/headers/Idempotent-Replayed'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Lead'
        '201':
          description: The new lead.
          headers:
            X-Request-ID:
              $ref: '#/components/headers/X-Request-ID'
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimit-Limit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimit-Remaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimit-Reset'
            Idempotent-Replayed:
              $ref: '#/components/headers/Idempotent-Replayed'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Lead'
        '429':
          $ref: '#/components/responses/RateLimited'
        4XX:
          $ref: '#/components/responses/Error'
        5XX:
          $ref: '#/components/responses/Error'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        Up to 255 characters. Repeat the key with the same body within 24 hours
        and you get the same response plus an Idempotent-Replayed header set to
        true. 402, 409, 429 and 5xx responses (except send_outcome_unknown) are
        not stored: fix the cause and retry with the same key.
      schema:
        type: string
        minLength: 1
        maxLength: 255
  schemas:
    LeadCreateRequest:
      type: object
      additionalProperties: false
      required:
        - text_agent_id
        - phone
      properties:
        text_agent_id:
          type: string
          format: uuid
        phone:
          $ref: '#/components/schemas/PhoneE164'
        name:
          type: string
          minLength: 1
          maxLength: 200
        status:
          $ref: '#/components/schemas/LeadStatus'
        variables:
          $ref: '#/components/schemas/LeadVariables'
    Lead:
      type: object
      additionalProperties: false
      required:
        - object
        - id
        - text_agent_id
        - voice_agent_id
        - contact_id
        - name
        - phone
        - email
        - username
        - channel
        - status
        - source
        - summary
        - variables
        - qualification
        - do_not_contact
        - has_replied
        - ai_paused
        - ai_paused_until
        - messaging_window_expires_at
        - created_at
        - last_activity_at
      properties:
        object:
          type: string
          const: lead
        id:
          type: string
          format: uuid
        text_agent_id:
          type:
            - string
            - 'null'
          format: uuid
          description: null if the lead belongs to a voice agent with no text agent.
        voice_agent_id:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            The voice agent, if the lead belongs to a voice agent with no text
            agent.
        contact_id:
          type: string
          format: uuid
          description: 'The person: several leads (one per channel) can be the same person.'
        name:
          type:
            - string
            - 'null'
        phone:
          type:
            - string
            - 'null'
          pattern: ^\+[1-9]\d{6,14}$
          description: In E.164.
        email:
          type:
            - string
            - 'null'
          description: >-
            The email address, if it is in the lead's variables (email,
            correo...), resolved the same way as in webhooks.
        username:
          type:
            - string
            - 'null'
          description: The Instagram username.
        channel:
          type: string
          enum:
            - whatsapp
            - instagram
            - webchat
            - email
            - meta_ads
            - voice
        status:
          $ref: '#/components/schemas/LeadStatus'
        source:
          $ref: '#/components/schemas/LeadSource'
        summary:
          type:
            - string
            - 'null'
        variables:
          type: object
          additionalProperties: true
          description: The customer variables. Platform variables are not returned.
        qualification:
          type: object
          additionalProperties: false
          required:
            - status
            - completed_at
            - answers
          properties:
            status:
              type: string
              enum:
                - not_started
                - in_progress
                - completed
                - disqualified
                - skipped
            completed_at:
              type:
                - string
                - 'null'
              format: date-time
            answers:
              type: array
              description: >-
                The qualification questions that apply to the lead and have an
                answer, in dashboard order; the same as in webhooks. Empty if
                the lead has answered none or the agent does not qualify leads.
              items:
                $ref: '#/components/schemas/QualificationAnswer'
        do_not_contact:
          type: boolean
          description: The lead asked not to be contacted.
        has_replied:
          type: boolean
        ai_paused:
          type: boolean
        ai_paused_until:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When the AI resumes; null if the pause has no end or there is no
            pause.
        messaging_window_expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            End of the 24-hour window for free-form text. On WhatsApp and
            Instagram, a past value means the window is closed. On other
            channels it does not apply and is null.
        created_at:
          type: string
          format: date-time
        last_activity_at:
          type: string
          format: date-time
          description: The last message or call; the creation time if there is none.
    PhoneE164:
      type: string
      pattern: ^\+[1-9]\d{6,14}$
      description: Phone number in E.164 format.
      examples:
        - '+34600111222'
    LeadStatus:
      type: string
      enum:
        - active
        - inactive
        - pending
        - closed
    LeadVariables:
      type: object
      description: >-
        Flat customer variables. They are merged with the lead's existing ones;
        null or "" deletes the key.
      maxProperties: 50
      propertyNames:
        minLength: 1
        maxLength: 100
        pattern: ^\S(?:.*\S)?$
      additionalProperties:
        type:
          - string
          - number
          - boolean
          - 'null'
        maxLength: 1000
    LeadSource:
      type: object
      additionalProperties: false
      required:
        - type
        - lead_ad
      description: Where the lead came from; the same block as in webhooks.
      properties:
        type:
          type:
            - string
            - 'null'
          examples:
            - whatsapp
            - meta_lead_form
            - webchat
        lead_ad:
          type:
            - object
            - 'null'
          additionalProperties: false
          required:
            - form_id
            - ad_id
            - leadgen_id
          properties:
            form_id:
              type:
                - string
                - 'null'
            ad_id:
              type:
                - string
                - 'null'
            leadgen_id:
              type:
                - string
                - 'null'
    QualificationAnswer:
      type: object
      additionalProperties: false
      required:
        - question_id
        - question
        - value
        - value_label
      properties:
        question_id:
          type: string
        question:
          type: string
          description: The question, as written in the qualification panel.
        value:
          type:
            - string
            - number
            - boolean
            - 'null'
          description: >-
            The answer: true or false for yes/no questions, a number, a date
            (2026-11-20), the value of the chosen option or text. null if the
            lead declined to answer.
        value_label:
          type:
            - string
            - 'null'
          description: >-
            The label of the chosen option on multiple-choice questions; null
            otherwise.
    ErrorResponse:
      type: object
      additionalProperties: false
      required:
        - error
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - type
            - code
            - message
            - param
            - request_id
            - doc_url
          properties:
            type:
              $ref: '#/components/schemas/ErrorType'
            code:
              $ref: '#/components/schemas/ErrorCode'
            message:
              type: string
              description: 'A human-readable explanation. It can change: never match on it.'
            param:
              type:
                - string
                - 'null'
              description: The offending field, dot-separated (variables.city), or null.
            request_id:
              type: string
              description: The same value as the x-request-id header.
            doc_url:
              type: string
              format: uri
            details:
              type: object
              additionalProperties: true
              description: >-
                On agent_not_ready, carries blockers. On send_outcome_unknown
                from POST /calls, carries call_id if the call is known.
      examples:
        - error:
            type: invalid_request_error
            code: parameter_invalid
            message: phone must match pattern "^\+[1-9]\d{6,14}$".
            param: phone
            request_id: req_m3k2a9_4f1c2b7e
            doc_url: https://docs.newlead.ai/errors#parameter_invalid
    ErrorType:
      type: string
      enum:
        - invalid_request_error
        - authentication_error
        - billing_error
        - permission_error
        - not_found_error
        - conflict_error
        - rate_limit_error
        - api_error
        - provider_error
    ErrorCode:
      type: string
      description: >-
        The closed list of error causes. The table is at
        https://docs.newlead.ai/errors.
      enum:
        - parameter_missing
        - parameter_invalid
        - parameter_unknown
        - body_invalid_json
        - recipient_invalid
        - api_key_missing
        - api_key_invalid
        - insufficient_balance
        - subscription_inactive
        - api_key_forbidden
        - feature_disabled
        - resource_not_found
        - route_not_found
        - agent_not_ready
        - lead_do_not_contact
        - lead_ai_paused
        - lead_ai_not_paused
        - messaging_window_closed
        - template_not_approved
        - outside_initiation_hours
        - voice_number_missing
        - webhook_endpoint_limit_reached
        - webhook_endpoint_disabled
        - idempotency_key_reused
        - idempotency_key_in_use
        - rate_limit_exceeded
        - internal_error
        - provider_unavailable
        - send_outcome_unknown
  headers:
    X-Request-ID:
      description: The id of this request. Quote it when you contact support.
      schema:
        type: string
    RateLimit-Limit:
      description: Requests allowed per minute for this API key.
      schema:
        type: integer
    RateLimit-Remaining:
      description: Requests left in the current minute.
      schema:
        type: integer
    RateLimit-Reset:
      description: Seconds until the counter resets.
      schema:
        type: integer
    Idempotent-Replayed:
      description: true when the response is the stored one for a repeated Idempotency-Key.
      schema:
        type: string
        const: 'true'
    Retry-After:
      description: Seconds to wait before repeating the request.
      schema:
        type: integer
  responses:
    RateLimited:
      description: Too many requests for this API key. Wait for Retry-After and repeat.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
        RateLimit-Limit:
          $ref: '#/components/headers/RateLimit-Limit'
        RateLimit-Remaining:
          $ref: '#/components/headers/RateLimit-Remaining'
        RateLimit-Reset:
          $ref: '#/components/headers/RateLimit-Reset'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Error:
      description: An error. type is the family and code is the cause.
      headers:
        X-Request-ID:
          $ref: '#/components/headers/X-Request-ID'
        RateLimit-Limit:
          $ref: '#/components/headers/RateLimit-Limit'
        RateLimit-Remaining:
          $ref: '#/components/headers/RateLimit-Remaining'
        RateLimit-Reset:
          $ref: '#/components/headers/RateLimit-Reset'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
        Idempotent-Replayed:
          $ref: '#/components/headers/Idempotent-Replayed'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        The API key, created in Settings › API, in the header Authorization:
        Bearer <key>. The default.
    ApiKeyHeader:
      type: apiKey
      in: header
      name: x-api-key
      description: The same key, in the x-api-key header. Still accepted.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.