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

# Batch import contacts

Creates or updates multiple contacts in a single batch operation. This is significantly more efficient than individual upsert operations. Optionally subscribes all contacts to specified lists.

## OpenAPI

````yaml /openapi.json post /api/contacts.import
openapi: 3.0.3
info:
  title: Notifuse API
  description: API for Notifuse - a transactional email and newsletter management platform
  version: 1.0.0
  contact:
    name: Notifuse Support
    url: https://www.notifuse.com/support
    email: hello@notifuse.com
  license:
    name: BUSL-1.1
    url: https://github.com/Notifuse/notifuse/blob/main/LICENSE
servers:
  - url: https://{notifuseDomain}
    description: Customer-specific Notifuse API server
    variables:
      notifuseDomain:
        description: Your unique Notifuse domain
        default: demo.notifuse.com
security: []
paths:
  /api/contacts.import:
    post:
      summary: Batch import contacts
      description: Creates or updates multiple contacts in a single batch operation.
        This is significantly more efficient than individual upsert operations.
        Optionally subscribes all contacts to specified lists.
      operationId: batchImportContacts
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BatchImportContactsRequest"
      responses:
        "200":
          description: Batch import completed (may include partial failures)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BatchImportContactsResponse"
        "400":
          description: Bad request - validation failed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                missingWorkspaceId:
                  value:
                    error: workspace_id is required
                missingContacts:
                  value:
                    error: contacts is required
                emptyContacts:
                  value:
                    error: contacts array cannot be empty
                insufficientPermissions:
                  value:
                    error: write access to lists required when subscribe_to_lists is provided
        "401":
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "500":
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
components:
  schemas:
    BatchImportContactsRequest:
      type: object
      required:
        - workspace_id
        - contacts
      properties:
        workspace_id:
          type: string
          description: The ID of the workspace
          example: ws_1234567890
        contacts:
          type: array
          description: Array of contacts to import (create or update)
          items:
            $ref: "#/components/schemas/ContactInput"
          minItems: 1
          example:
            - email: user1@example.com
              first_name: John
              last_name: Doe
            - email: user2@example.com
              first_name: Jane
              last_name: Smith
        subscribe_to_lists:
          type: array
          description: Optional array of list IDs to subscribe all contacts to
          items:
            type: string
          example:
            - newsletter
            - product_updates
    BatchImportContactsResponse:
      type: object
      properties:
        operations:
          type: array
          description: Array of operation results, one for each contact in the request
          items:
            $ref: "#/components/schemas/UpsertContactOperation"
        error:
          type: string
          nullable: true
          description: Global error message if the entire operation failed
          example: null
    ContactInput:
      type: object
      required:
        - email
      properties:
        email:
          type: string
          format: email
          description: Email address of the contact. This is the contact's unique
            identifier — upserts always match contacts by email address.
          example: user@example.com
        external_id:
          type: string
          nullable: true
          description: Optional identifier for the contact in your own system (e.g. your
            user ID). Stored and searchable, but not unique and never used to
            match contacts during upserts — sending an existing external_id with
            a new email address creates a second contact.
          example: user_12345
        timezone:
          type: string
          nullable: true
          description: Timezone of the contact
          example: America/New_York
        language:
          type: string
          nullable: true
          description: Preferred language of the contact
          example: en-US
        first_name:
          type: string
          nullable: true
          description: First name of the contact
          example: John
        last_name:
          type: string
          nullable: true
          description: Last name of the contact
          example: Doe
        full_name:
          type: string
          nullable: true
          description: Full name of the contact (for systems that don't have separate
            first/last names)
          example: John Doe
        phone:
          type: string
          nullable: true
          description: Phone number of the contact
          example: "+15551234567"
        address_line_1:
          type: string
          nullable: true
          description: First line of address
          example: 123 Main St
        address_line_2:
          type: string
          nullable: true
          description: Second line of address
          example: Apt 4B
        country:
          type: string
          nullable: true
          description: Country of the contact
          example: US
        postcode:
          type: string
          nullable: true
          description: Postal code
          example: "10001"
        state:
          type: string
          nullable: true
          description: State or province
          example: NY
        job_title:
          type: string
          nullable: true
          description: Job title of the contact
          example: Software Engineer
        tracking_opens_consent:
          type: string
          nullable: true
          enum:
            - granted
            - denied
            - null
          description: >
            The contact's own choice about open tracking. `granted` or `denied`
            override the

            workspace's rule for contacts without a recorded choice; `null` (or
            absent on

            create) means unknown. Opens are tracked only when the workspace
            tracks them and

            this choice allows it.
          example: denied
        tracking_clicks_consent:
          type: string
          nullable: true
          enum:
            - granted
            - denied
            - null
          description: The contact's own choice about click tracking, with the same rules
            as `tracking_opens_consent`.
          example: granted
        tracking_consent_updated_at:
          type: string
          format: date-time
          nullable: true
          description: >
            When the tracking choice changed. Set by the server when a consent
            value changes and

            this field is not given.
        tracking_consent_source:
          type: string
          nullable: true
          maxLength: 50
          description: >
            Where the change came from. Defaults to `api` for an API key and
            `console` for a

            console user; an import uses `import`. Known values: api, console,
            import,

            notification_center, email_link, subscribe_form.
          example: api
        custom_string_1:
          type: string
          nullable: true
          description: Custom string field 1
          example: Premium tier
        custom_string_2:
          type: string
          nullable: true
          description: Custom string field 2
        custom_string_3:
          type: string
          nullable: true
          description: Custom string field 3
        custom_string_4:
          type: string
          nullable: true
          description: Custom string field 4
        custom_string_5:
          type: string
          nullable: true
          description: Custom string field 5
        custom_number_1:
          type: number
          format: float
          nullable: true
          description: Custom number field 1
          example: 42
        custom_number_2:
          type: number
          format: float
          nullable: true
          description: Custom number field 2
        custom_number_3:
          type: number
          format: float
          nullable: true
          description: Custom number field 3
        custom_number_4:
          type: number
          format: float
          nullable: true
          description: Custom number field 4
        custom_number_5:
          type: number
          format: float
          nullable: true
          description: Custom number field 5
        custom_datetime_1:
          type: string
          format: date-time
          nullable: true
          description: Custom datetime field 1
          example: 2023-06-01T09:00:00Z
        custom_datetime_2:
          type: string
          format: date-time
          nullable: true
          description: Custom datetime field 2
        custom_datetime_3:
          type: string
          format: date-time
          nullable: true
          description: Custom datetime field 3
        custom_datetime_4:
          type: string
          format: date-time
          nullable: true
          description: Custom datetime field 4
        custom_datetime_5:
          type: string
          format: date-time
          nullable: true
          description: Custom datetime field 5
        custom_json_1:
          description: Custom JSON field 1. Any JSON value the jsonb column can hold — an
            object, an array, a string, a number, a boolean, or null to clear
            it.
          example:
            preferences:
              theme: dark
              notifications: true
        custom_json_2:
          description: Custom JSON field 2. Any JSON value the jsonb column can hold.
        custom_json_3:
          description: Custom JSON field 3. Any JSON value the jsonb column can hold.
        custom_json_4:
          description: Custom JSON field 4. Any JSON value the jsonb column can hold.
        custom_json_5:
          description: Custom JSON field 5. Any JSON value the jsonb column can hold.
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Error message
      required:
        - error
    UpsertContactOperation:
      type: object
      properties:
        email:
          type: string
          format: email
          description: Email address of the contact
          example: user@example.com
        action:
          type: string
          enum:
            - create
            - update
            - error
          description: "The action that was performed: 'create' for new contacts, 'update'
            for existing contacts, 'error' for failed operations"
          example: create
        error:
          type: string
          nullable: true
          description: Error message if this specific contact operation failed
          example: null
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API token for authentication
````
