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

# Upsert contacts

> Create or update up to 100 contacts in one request (note: this endpoint's batch limit is 100 items). Each item is matched against existing contacts by a single key: the normalized `email` when the item has a non-empty email, otherwise the normalized `phone`. A matched contact is updated with the item's remaining fields (`status: updated`); an unmatched item creates a new contact (`status: created`, with `original_source` defaulting to `Public API` and `original_source_detail` to `client_item_id` unless supplied).

Because matching uses only that single key, an item whose email is new but whose phone already belongs to a different contact is **not** treated as an update — the creation collides on the phone and the item is rejected with `error_code: conflict` and the conflicting contact in `existing_contact`. (A create collision on the item's own match key — e.g. from a concurrent insert — is resolved as an update of that contact instead.) Updates that would change an email or phone to collide with another contact are likewise rejected with `conflict`, and updates that would leave a contact with neither a valid email nor phone are rejected with `bad_request`.

Partial success is normal — inspect each item result; successful items include the full `contact` with `custom_fields`. Body-level validation failures (an invalid email or phone format, more than 100 items, unknown fields) reject the entire request with `400` before any item is processed.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/contacts/upsert
openapi: 3.1.0
info:
  title: Tented API
  version: 1.0.0
  description: >-
    The Tented public API: generate, publish, and manage AI-built web pages
    (tents), and run the email platform — contacts, reusable emails, one-time
    blasts, and triggered flows.


    ## Authentication

    Authenticate every request with a workspace API key: `Authorization: Bearer
    <api-key>`. Keys are created in **Workspace Settings → API Keys** and are
    scoped to a single workspace.


    ## Asynchronous work

    Tent generation, bulk creation, and email AI generation return `202
    Accepted` immediately. Poll the corresponding status endpoint (`GET
    /v1/tents/{tentId}`, `GET /v1/bulk-jobs/{bulkJobId}`, `GET
    /v1/emails/{emailId}/generations/{generationId}`) — no more than every 10
    seconds.


    ## Pagination

    Email listings use cursor pagination (`cursor`/`next_cursor`). Blast, flow,
    and member listings use page pagination (`page`/`limit` with a `pagination`
    object in the response).


    ## Conventions

    Request and response fields are snake_case, with two exceptions: analytics
    query parameters (`tentIdOrAlias`, `daysBack`) and segment rule trees
    (camelCase keys such as `listId` and `timeWindow`).
  contact:
    name: Tented Support
    email: support@tented.ai
servers:
  - url: https://api.tented.ai
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Tents
    description: >-
      Create, edit, publish, and manage AI-generated pages, including asset
      uploads and bulk creation.
  - name: Analytics
    description: Traffic analytics for single tents and the whole workspace.
  - name: Contacts
    description: >-
      Batch create, update, and delete contacts. Up to 25 items per request with
      per-item results.
  - name: Emails
    description: >-
      Reusable email content: AI generation, direct HTML edits, plain-text
      control, and approval.
  - name: Email Blasts
    description: >-
      One-time sends to an audience: compose, schedule, track engagement, export
      recipients.
  - name: Triggered Flows
    description: >-
      Multi-step automations that enroll contacts on triggers and move them
      through a step graph.
  - name: Contact Imports
  - name: Contact Fields
  - name: Contact Lists
  - name: Email Templates
  - name: Tent Templates
    description: >-
      Reusable, AI-editable tent layouts. Create from HTML or an existing tent,
      iterate with AI, approve, and clone. Approved tent templates seed new
      tents.
paths:
  /v1/contacts/upsert:
    post:
      tags:
        - Contacts
      summary: Upsert contacts
      description: >-
        Create or update up to 100 contacts in one request (note: this
        endpoint's batch limit is 100 items). Each item is matched against
        existing contacts by a single key: the normalized `email` when the item
        has a non-empty email, otherwise the normalized `phone`. A matched
        contact is updated with the item's remaining fields (`status: updated`);
        an unmatched item creates a new contact (`status: created`, with
        `original_source` defaulting to `Public API` and
        `original_source_detail` to `client_item_id` unless supplied).


        Because matching uses only that single key, an item whose email is new
        but whose phone already belongs to a different contact is **not**
        treated as an update — the creation collides on the phone and the item
        is rejected with `error_code: conflict` and the conflicting contact in
        `existing_contact`. (A create collision on the item's own match key —
        e.g. from a concurrent insert — is resolved as an update of that contact
        instead.) Updates that would change an email or phone to collide with
        another contact are likewise rejected with `conflict`, and updates that
        would leave a contact with neither a valid email nor phone are rejected
        with `bad_request`.


        Partial success is normal — inspect each item result; successful items
        include the full `contact` with `custom_fields`. Body-level validation
        failures (an invalid email or phone format, more than 100 items, unknown
        fields) reject the entire request with `400` before any item is
        processed.
      operationId: upsert-contacts
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                items:
                  type: array
                  items:
                    $ref: '#/components/schemas/ContactUpsertItem'
                  minItems: 1
                  maxItems: 100
                  description: Contacts to create or update (1–100).
              required:
                - items
      responses:
        '200':
          description: Batch processed (individual items may still be rejected).
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    description: Always `completed` once the batch has been processed.
                  created_count:
                    type: integer
                    description: Contacts created.
                  updated_count:
                    type: integer
                    description: Contacts updated.
                  rejected_count:
                    type: integer
                    description: Number of rejected items.
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ContactBatchItemResult'
                    description: >-
                      Per-item results, in request order. Created and updated
                      items include the full `contact` (with `custom_fields`).
                required:
                  - status
                  - created_count
                  - updated_count
                  - rejected_count
                  - items
        '400':
          description: >-
            Bad request — invalid parameters or request body. Validation
            failures include `details.issues` with per-field messages and reject
            the entire batch.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized — missing, malformed, revoked, or expired API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ContactUpsertItem:
      type: object
      properties:
        client_item_id:
          type: string
          description: >-
            Optional ID echoed back in the result for reconciliation. Also used
            as `original_source_detail` for created contacts when
            `original_source_detail` is not supplied.
        email:
          type:
            - string
            - 'null'
          description: >-
            Email address. When non-empty, this is the item's match key: the
            contact whose normalized email matches is updated. Pass `null` to
            clear the email of a phone-matched contact (only allowed if a valid
            phone remains).
        phone:
          type:
            - string
            - 'null'
          description: >-
            Phone number. Used as the match key only when `email` is absent or
            empty; otherwise it is stored as a regular field update. Pass `null`
            to clear (only allowed if a valid email remains).
        display_name:
          type:
            - string
            - 'null'
          maxLength: 255
          description: Display name. Pass `null` to clear.
        first_name:
          type:
            - string
            - 'null'
          maxLength: 255
          description: First name. Pass `null` to clear.
        last_name:
          type:
            - string
            - 'null'
          maxLength: 255
          description: Last name. Pass `null` to clear.
        email_domain:
          type:
            - string
            - 'null'
          description: Usually auto-derived from `email`.
          maxLength: 255
        company:
          type:
            - string
            - 'null'
          maxLength: 255
          description: Company. Pass `null` to clear.
        job_title:
          type:
            - string
            - 'null'
          maxLength: 255
          description: Job title. Pass `null` to clear.
        address:
          type:
            - string
            - 'null'
          maxLength: 500
          description: Street address. Pass `null` to clear.
        address2:
          type:
            - string
            - 'null'
          maxLength: 255
          description: Address line 2. Pass `null` to clear.
        city:
          type:
            - string
            - 'null'
          maxLength: 255
          description: City. Pass `null` to clear.
        state:
          type:
            - string
            - 'null'
          maxLength: 255
          description: State or region. Pass `null` to clear.
        country:
          type:
            - string
            - 'null'
          maxLength: 255
          description: Country. Pass `null` to clear.
        zip_code:
          type:
            - string
            - 'null'
          maxLength: 50
          description: Postal code. Pass `null` to clear.
        original_source:
          type:
            - string
            - 'null'
          maxLength: 255
          description: >-
            Original source. For created contacts, defaults to `Public API` when
            omitted or empty.
        original_source_detail:
          type:
            - string
            - 'null'
          maxLength: 255
          description: >-
            Original source detail. For created contacts, defaults to
            `client_item_id` when omitted or empty.
        lead_status:
          type:
            - string
            - 'null'
          maxLength: 100
          description: Lead status. Pass `null` to clear.
        lifecycle_stage:
          type:
            - string
            - 'null'
          maxLength: 100
          description: Lifecycle stage. Pass `null` to clear.
        tented_score:
          type:
            - number
            - 'null'
          description: Contact score. Pass `null` to clear.
        unsubscribed:
          type: boolean
          description: Global unsubscribe flag.
        marketing_email_subscribed:
          type:
            - boolean
            - 'null'
          description: Email marketing subscription state.
        marketing_sms_subscribed:
          type:
            - boolean
            - 'null'
          description: SMS marketing subscription state.
        marketing_sms_invalid:
          type: boolean
          description: Mark the phone number invalid.
        custom_fields:
          type: object
          additionalProperties:
            type:
              - string
              - number
              - boolean
              - 'null'
          description: >-
            Editable custom fields keyed by API name. Pass `null` to clear a
            value.
      description: >-
        A contact to create or update. Must include a non-empty `email` or
        `phone` to identify the contact; unknown fields are rejected.
    ContactBatchItemResult:
      type: object
      properties:
        index:
          type: integer
          description: Zero-based position in the request `items` array.
        client_item_id:
          type: string
          description: Your reconciliation ID, echoed back when supplied.
        contact_id:
          type: string
          format: uuid
          description: Contact ID (when known).
        status:
          type: string
          enum:
            - created
            - updated
            - deleted
            - rejected
          description: Outcome for this item.
        contact:
          $ref: '#/components/schemas/Contact'
        error_code:
          type: string
          enum:
            - bad_request
            - not_found
            - conflict
            - error
          description: Rejection code.
        message:
          type: string
          description: Human-readable rejection reason.
        existing_contact:
          type: object
          properties:
            contact_id:
              type: string
              format: uuid
              description: ID of the conflicting contact.
            display_name:
              type:
                - string
                - 'null'
              description: Display name.
            email:
              type:
                - string
                - 'null'
              description: Email address.
            phone:
              type:
                - string
                - 'null'
              description: Phone number.
          description: The already-existing contact, included on `conflict` rejections.
      required:
        - index
        - status
    Error:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message.
        error_code:
          type: string
          description: >-
            Stable machine-readable error code (present on email, blast, flow,
            and related endpoints, e.g. `campaign_not_ready`,
            `generation_in_progress`).
        message:
          type: string
          description: Additional human-readable context (present on some tent endpoints).
        code:
          type: string
          description: >-
            Machine-readable code used by tent creation errors (e.g.
            `INVALID_PROMPT_INTENT`).
        details:
          type: object
          additionalProperties: true
          description: >-
            Additional error context. Validation errors include `issues`: an
            array of `{ path, message }` objects.
        limit:
          type: integer
          description: Plan limit that was hit (present on `429` publish-limit errors).
        current:
          type: integer
          description: >-
            Current usage against the limit (present on `429` publish-limit
            errors).
      required:
        - error
      description: >-
        Error response. All errors include `error`; the other fields vary by
        endpoint group.
    Contact:
      type: object
      properties:
        contact_id:
          type: string
          format: uuid
          description: Contact ID.
        display_name:
          type:
            - string
            - 'null'
          description: Display name.
        first_name:
          type:
            - string
            - 'null'
          description: First name.
        last_name:
          type:
            - string
            - 'null'
          description: Last name.
        email:
          type:
            - string
            - 'null'
          description: Email address.
        phone:
          type:
            - string
            - 'null'
          description: Phone number.
        email_domain:
          type:
            - string
            - 'null'
          description: Domain derived from the email address.
        company:
          type:
            - string
            - 'null'
          description: Company.
        job_title:
          type:
            - string
            - 'null'
          description: Job title.
        address:
          type:
            - string
            - 'null'
          description: Street address.
        address2:
          type:
            - string
            - 'null'
          description: Address line 2.
        city:
          type:
            - string
            - 'null'
          description: City.
        state:
          type:
            - string
            - 'null'
          description: State or region.
        country:
          type:
            - string
            - 'null'
          description: Country.
        zip_code:
          type:
            - string
            - 'null'
          description: Postal code.
        original_source:
          type:
            - string
            - 'null'
          description: How the contact was first created, e.g. `Public API`.
        original_source_detail:
          type:
            - string
            - 'null'
          description: Additional source detail.
        lead_status:
          type:
            - string
            - 'null'
          description: Lead status.
        lifecycle_stage:
          type:
            - string
            - 'null'
          description: Lifecycle stage.
        tented_score:
          type:
            - number
            - 'null'
          description: Contact score.
        unsubscribed:
          type: boolean
          description: Global unsubscribe flag.
        marketing_email_subscribed:
          type:
            - boolean
            - 'null'
          description: Email marketing subscription state.
        marketing_sms_subscribed:
          type:
            - boolean
            - 'null'
          description: SMS marketing subscription state.
        marketing_email_invalid:
          type: boolean
          description: Whether the email address is known to be invalid.
        marketing_sms_invalid:
          type: boolean
          description: Whether the phone number is known to be invalid.
        last_activity_at:
          type:
            - string
            - 'null'
          format: date-time
          description: Most recent tracked activity.
        created_at:
          type: string
          format: date-time
          description: Creation time.
        updated_at:
          type: string
          format: date-time
          description: Last update.
      description: A contact record. Fields that were never set are omitted.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Workspace API key, e.g. `Authorization: Bearer tented_...`. Create keys
        in Workspace Settings → API Keys.

````