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

# Upsert contacts

> Create or update 1-1,000 people, matched by email. `mode` decides what happens to people who already exist (default `fill_empty`); a missing or empty value never erases a field, and the tags you send are added to the person's (an upsert never removes a tag; PATCH replaces them). A contact that fails validation is reported in `invalidRows` and the rest are saved. New people beyond the fair use of contact storage are not saved (`over_storage_limit`); if nobody in the request can be saved (all valid emails are new people and none fit), the request fails with 402. The body is limited to 1 MB: a bigger one fails with 413 `request_too_large`, so send full profiles in smaller requests.

Requires one of the following scopes: `contacts:write`, `contacts:all`, `all:all`.



## OpenAPI

````yaml /openapi.json post /v1/contacts
openapi: 3.0.0
info:
  title: MailBeast Public API
  description: >-
    Task-shaped REST API for campaigns, leads, deliverability, verification and
    lead discovery. Authenticate with an API key (`Authorization: Bearer
    mb_live_…`); the workspace is resolved from the key.
  version: '1'
  contact: {}
servers:
  - url: https://api.mailbeast.ai
security: []
tags:
  - name: API Keys
    description: Create, list and delete API keys programmatically.
  - name: Campaigns
    description: Create, configure, launch and monitor email campaigns.
  - name: Subsequences
    description: >-
      Follow-up flows of a campaign that start on a lead status, a reply, an
      open, a click or a finished sequence - from the same mailbox, in the same
      thread.
  - name: Leads
    description: Add, read, update and bulk-manage a campaign’s leads.
  - name: Contacts
    description: >-
      The people of the workspace, one per email across all campaigns: list,
      upsert, update and delete.
  - name: Workspace
    description: Read usage, subscription and workspace identity.
  - name: Email Accounts
    description: >-
      Connect and manage the sending mailboxes your campaigns send from
      (SMTP/IMAP or native OAuth).
  - name: Analytics
    description: Engagement reporting – per campaign, over time, and across the workspace.
  - name: Lead Finder
    description: >-
      Discover new companies and leads. List past searches and poll a running
      search’s progress.
paths:
  /v1/contacts:
    post:
      tags:
        - Contacts
      summary: Upsert contacts
      description: >-
        Create or update 1-1,000 people, matched by email. `mode` decides what
        happens to people who already exist (default `fill_empty`); a missing or
        empty value never erases a field, and the tags you send are added to the
        person's (an upsert never removes a tag; PATCH replaces them). A contact
        that fails validation is reported in `invalidRows` and the rest are
        saved. New people beyond the fair use of contact storage are not saved
        (`over_storage_limit`); if nobody in the request can be saved (all valid
        emails are new people and none fit), the request fails with 402. The
        body is limited to 1 MB: a bigger one fails with 413
        `request_too_large`, so send full profiles in smaller requests.


        Requires one of the following scopes: `contacts:write`, `contacts:all`,
        `all:all`.
      operationId: contacts_upsert
      parameters:
        - name: Idempotency-Key
          in: header
          description: >-
            Optional. A unique key you generate (max 255 chars, such as a UUID)
            that makes this request safe to retry. Retrying with the same key
            replays the original response instead of repeating the operation.
            Reusing a key with a different body returns `422`.
          required: false
          schema:
            type: string
            maxLength: 255
            example: a1b2c3d4-e5f6-7890-abcd-ef1234567890
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertContactsApiDto'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertContactsApiResponseDto'
        '400':
          description: The request body or parameters failed validation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
              example:
                error:
                  type: invalid_request_error
                  code: validation_failed
                  message: One or more fields are invalid.
                  status: 400
                  requestId: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
                  details:
                    - name should not be empty
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
              example:
                error:
                  type: authentication_error
                  code: unauthenticated
                  message: Missing or invalid API key.
                  status: 401
                  requestId: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
        '402':
          description: A plan limit was reached - top up or upgrade.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
              example:
                error:
                  type: invalid_request_error
                  code: plan_limit_exceeded
                  message: A plan limit was reached.
                  status: 402
                  requestId: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
        '403':
          description: >-
            The key lacks a required scope, or the plan does not include API
            access.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
              example:
                error:
                  type: authorization_error
                  code: permission_denied
                  message: This API key is missing the required scope.
                  status: 403
                  requestId: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
        '409':
          description: >-
            The request conflicts with current state - e.g. a request with the
            same Idempotency-Key is still being processed, or the operation
            partially applied.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
              example:
                error:
                  type: invalid_request_error
                  code: conflict
                  message: The request conflicts with an existing resource.
                  status: 409
                  requestId: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
        '422':
          description: >-
            The Idempotency-Key was already used with a different request body.
            Use a new key for a new operation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
              example:
                error:
                  type: invalid_request_error
                  code: idempotency_key_reused
                  message: >-
                    The Idempotency-Key was already used with a different
                    request body. Use a new key for a new operation.
                  status: 422
                  requestId: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
        '429':
          description: >-
            Rate limit exceeded - retry after the interval in the Retry-After
            header.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
              example:
                error:
                  type: rate_limit_error
                  code: rate_limited
                  message: >-
                    Too many requests. Retry after the interval in the
                    Retry-After header.
                  status: 429
                  requestId: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
                  retryAfter: 30
      security:
        - ApiKey: []
components:
  schemas:
    UpsertContactsApiDto:
      type: object
      properties:
        contacts:
          minItems: 1
          maxItems: 1000
          description: >-
            1-1000 people, matched by email (case-insensitive). The request body
            is limited to 1 MB.
          type: array
          items:
            $ref: '#/components/schemas/ContactInputApiDto'
        mode:
          type: string
          enum:
            - fill_empty
            - overwrite
            - skip
          default: fill_empty
          description: >-
            What to do with a person who already exists: `fill_empty` fills only
            their empty fields, `overwrite` replaces fields with the values you
            send, `skip` leaves them as they are. In both `fill_empty` and
            `overwrite` the tags you send are added to the person's tags: an
            upsert never removes a tag (PATCH replaces them). A missing or empty
            value never erases a field.
      required:
        - contacts
    UpsertContactsApiResponseDto:
      type: object
      properties:
        summary:
          $ref: '#/components/schemas/ContactUpsertSummaryDto'
        results:
          description: Each valid email once, in request order.
          type: array
          items:
            $ref: '#/components/schemas/ContactUpsertResultApiDto'
        invalidRows:
          type: array
          items:
            $ref: '#/components/schemas/ContactUpsertInvalidRowApiDto'
      required:
        - summary
        - results
        - invalidRows
    ApiErrorDto:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ApiErrorBodyDto'
      required:
        - error
    ContactInputApiDto:
      type: object
      properties:
        firstName:
          type: string
          nullable: true
          maxLength: 128
        lastName:
          type: string
          nullable: true
          maxLength: 128
        companyName:
          type: string
          nullable: true
          maxLength: 256
        jobTitle:
          type: string
          nullable: true
          maxLength: 128
        website:
          type: string
          nullable: true
          maxLength: 512
        linkedinProfile:
          type: string
          nullable: true
          maxLength: 512
        location:
          type: string
          nullable: true
          maxLength: 128
        tags:
          type: array
          nullable: true
          items:
            type: string
            minLength: 1
            maxLength: 64
          maxItems: 50
          example:
            - vip
        customFields:
          type: object
          description: >-
            Custom fields by key (`{{custom_<key>}}` in templates). A key you
            send is set, a key you leave out is kept. On an update `null` or
            `""` clears that key and `customFields: null` clears them all; on an
            upsert empty values are ignored and `mode` decides whether existing
            values change. A value of an image or url field must be an absolute
            http(s) URL.
          nullable: true
        customFieldLabels:
          type: object
          description: >-
            Labels of NEW custom fields of the workspace (key → label), as the
            lead editor sends them. An existing field keeps its own label.
        customFieldTypes:
          type: object
          description: >-
            Types of NEW custom fields of the workspace (key → text | url |
            number | date | image). An existing field keeps its own type.
        email:
          type: string
          example: anna@northwind.io
          format: email
          maxLength: 254
      required:
        - email
    ContactUpsertSummaryDto:
      type: object
      properties:
        submitted:
          type: number
          example: 4
        created:
          type: number
          example: 1
        updated:
          type: number
          example: 1
        unchanged:
          type: number
          example: 0
        skipped:
          type: number
          example: 0
        invalid:
          type: number
          example: 1
          description: Contacts that failed validation (see `invalidRows`).
        duplicates:
          type: number
          example: 1
          description: >-
            Repeats of an email earlier in the same request (merged into one
            person).
        overStorageLimit:
          type: number
          example: 0
      required:
        - submitted
        - created
        - updated
        - unchanged
        - skipped
        - invalid
        - duplicates
        - overStorageLimit
    ContactUpsertResultApiDto:
      type: object
      properties:
        email:
          type: string
          example: anna@northwind.io
          description: The email as stored (lowercase, trimmed).
        contactId:
          type: string
          format: uuid
          nullable: true
          description: null only for `over_storage_limit`.
        outcome:
          type: string
          enum:
            - created
            - updated
            - unchanged
            - skipped
            - over_storage_limit
          description: >-
            `created` new person; `updated` existing person, fields changed;
            `unchanged` nothing to change; `skipped` existing person left as is
            (`mode: skip`); `over_storage_limit` new person not saved: contact
            storage is at its fair use.
      required:
        - email
        - outcome
    ContactUpsertInvalidRowApiDto:
      type: object
      properties:
        index:
          type: number
          example: 3
          description: Index in `contacts` (from 0).
        reason:
          type: string
          example: website must be a URL address
      required:
        - index
        - reason
    ApiErrorBodyDto:
      type: object
      properties:
        type:
          type: string
          example: authorization_error
          description: Broad error class.
        code:
          type: string
          example: permission_denied
          description: Stable machine-readable code to switch on.
        message:
          type: string
          example: This API key is missing the required scope.
        status:
          type: number
          example: 403
        requestId:
          type: string
          example: e4f1c0b2-6a3d-4b8e-9f21-0a1b2c3d4e5f
          description: Correlation id - quote it in support requests.
        details:
          description: Field-level validation messages (present on validation errors).
          example:
            - name should not be empty
          type: array
          items:
            type: string
        retryAfter:
          type: number
          description: Seconds to wait before retrying (present on 429 responses).
          example: 30
      required:
        - type
        - code
        - message
        - status
        - requestId
  securitySchemes:
    ApiKey:
      scheme: bearer
      bearerFormat: mb_live_…
      type: http

````

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