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

# Create or attach a user (idempotent via Idempotency-Key)



## OpenAPI

````yaml https://api.develop.fourdos.dev/openapi/partner.json post /v1/users
openapi: 3.1.0
info:
  title: 4D OS Partner API
  version: 0.1.0
  description: >-
    REST API for 4D OS partners. Authenticate with your organization API key:
    `Authorization: Bearer <key>`.


    Requests and responses are JSON with `snake_case` field names. Errors share
    one envelope: `{ "error": { "code", "status", "message", "details"? } }`.


    Mutating endpoints that declare it accept an `Idempotency-Key` header so
    retries are safe.


    Bulk-migrating members? See the [Migrating to 4D
    guide](https://docs.fourdos.dev/walkthroughs/migrate-existing-members) for
    the canonical import schema, a worked example, and the `/v1/imports`
    sequence.
servers: []
security:
  - partnerApiKey: []
tags:
  - name: Users
    description: Create, read, and manage users and their org membership
  - name: Imports
    description: Bulk member import jobs (staging → validate → commit)
  - name: Engagement
    description: Browser event tracking (publishable keys) and tracking-key management
paths:
  /v1/users:
    post:
      tags:
        - Users
      summary: Create or attach a user (idempotent via Idempotency-Key)
      operationId: createOrAttachUser
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateUserBody'
      responses:
        '200':
          description: Existing user/member returned unchanged
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserResponse'
        '201':
          description: User and/or membership created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserResponse'
        '409':
          description: Idempotency or external_id conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CreateUserBody:
      type: object
      properties:
        email:
          type: string
          format: email
          pattern: >-
            ^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$
        external_id:
          type: string
        display_name:
          type: string
        locale:
          type: string
        first_name:
          type: string
        last_name:
          type: string
        country:
          type: string
          pattern: ^[A-Za-z]{2}$
        dob:
          type: string
          pattern: ^\d{4}-\d{2}-\d{2}$
      required:
        - email
    UserResponse:
      type: object
      properties:
        id:
          type: string
        email:
          type: string
        display_name:
          anyOf:
            - type: string
            - type: 'null'
        first_name:
          anyOf:
            - type: string
            - type: 'null'
        last_name:
          anyOf:
            - type: string
            - type: 'null'
        country:
          anyOf:
            - type: string
            - type: 'null'
        age_band:
          type: string
          enum:
            - under_13
            - '13_15'
            - '16_17'
            - adult
            - unknown
        dob_verification_status:
          type: string
          enum:
            - unverified
            - self_declared
            - verified
        last_active_at:
          anyOf:
            - type: string
            - type: 'null'
        status:
          type: string
          enum:
            - active
            - locked
            - deleted
        wallet:
          anyOf:
            - type: object
              properties:
                status:
                  type: string
                  enum:
                    - provisioning
                    - active
                    - failed
                    - destroyed
                address:
                  anyOf:
                    - type: string
                    - type: 'null'
              required:
                - status
                - address
            - type: 'null'
        membership:
          type: object
          properties:
            id:
              type: string
            external_id:
              anyOf:
                - type: string
                - type: 'null'
            role:
              type: string
              enum:
                - member
                - partner_admin
            status:
              type: string
              enum:
                - active
                - locked
                - removed
            joined_at:
              type: string
            locked_at:
              anyOf:
                - type: string
                - type: 'null'
            locked_reason:
              anyOf:
                - type: string
                - type: 'null'
          required:
            - id
            - external_id
            - role
            - status
            - joined_at
            - locked_at
            - locked_reason
      required:
        - id
        - email
        - display_name
        - first_name
        - last_name
        - country
        - age_band
        - dob_verification_status
        - last_active_at
        - status
        - wallet
        - membership
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            status:
              type: integer
            message:
              type: string
            details:
              type: object
              additionalProperties: true
          required:
            - code
            - status
            - message
      required:
        - error
  securitySchemes:
    partnerApiKey:
      type: http
      scheme: bearer
      description: >-
        Organization API key (`org_…`), sent as `Authorization: Bearer <key>`.
        Keys are scoped to one organization; every request operates within that
        tenant.

````