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

# Bulk upsert items

> Creates or upserts up to 5000 items in one call. Use for tenant migrations, importer runs, replays of an external source. Replaces the historical `/import` endpoint.

Modes: `upsert` (default) matches existing rows on `(source, source_id)` and updates in place — properties shallow-merge, tags replace if provided, edges union-merge if provided; `create_only` surfaces matching rows as `skipped`. Atomic by default — `atomic: true` wraps the batch in one transaction; `atomic: false` runs per-item with per-item outcomes. `emit_events: false` is the default; opt in with `emit_events: true` if subscribers should fan out per item.

Inline `edges` blocks on items have replace-all-per-type semantics within the batch. For cross-batch edges, use `POST /edges/bulk` after items land.

Admin-only. `source` is server-stamped from the credential — any caller-supplied `source` is silently overwritten. See [Bulk operations](/api/bulk-operations).



## OpenAPI

````yaml /openapi.json post /items/bulk
openapi: 3.1.0
info:
  title: Marfa API
  version: 4.2.0
  description: Typed data layer for structured personal data
servers: []
security: []
paths:
  /items/bulk:
    post:
      tags:
        - Items
      summary: Bulk upsert items
      description: >-
        Creates or upserts up to 5000 items in one call. Use for tenant
        migrations, importer runs, replays of an external source. Replaces the
        historical `/import` endpoint.


        Modes: `upsert` (default) matches existing rows on `(source, source_id)`
        and updates in place — properties shallow-merge, tags replace if
        provided, edges union-merge if provided; `create_only` surfaces matching
        rows as `skipped`. Atomic by default — `atomic: true` wraps the batch in
        one transaction; `atomic: false` runs per-item with per-item outcomes.
        `emit_events: false` is the default; opt in with `emit_events: true` if
        subscribers should fan out per item.


        Inline `edges` blocks on items have replace-all-per-type semantics
        within the batch. For cross-batch edges, use `POST /edges/bulk` after
        items land.


        Admin-only. `source` is server-stamped from the credential — any
        caller-supplied `source` is silently overwritten. See [Bulk
        operations](/api/bulk-operations).
      operationId: bulkUpsertItems
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      id:
                        type: string
                      type:
                        type: string
                      properties:
                        type: object
                        additionalProperties:
                          nullable: true
                      state:
                        type: string
                        enum:
                          - active
                          - archived
                          - trashed
                      tier:
                        type: string
                        enum:
                          - library
                          - feed
                      timestamp:
                        type: string
                      source:
                        type: string
                      source_id:
                        type: string
                      device:
                        type: string
                      tags:
                        type: array
                        items:
                          type: string
                      edges:
                        type: object
                        additionalProperties:
                          type: array
                          items:
                            type: string
                    required:
                      - type
                mode:
                  type: string
                  enum:
                    - upsert
                    - create_only
                atomic:
                  type: boolean
                emit_events:
                  type: boolean
              required:
                - items
      responses:
        '200':
          description: Bulk upsert result
          content:
            application/json:
              schema:
                type: object
                properties:
                  counts:
                    type: object
                    properties:
                      created:
                        type: integer
                      updated:
                        type: integer
                      skipped:
                        type: integer
                      errored:
                        type: integer
                    required:
                      - created
                      - updated
                      - skipped
                      - errored
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                        outcome:
                          type: string
                          enum:
                            - created
                            - updated
                            - skipped
                            - errored
                        id:
                          type: string
                        reason:
                          type: string
                        error:
                          type: object
                          properties:
                            code:
                              type: string
                            message:
                              type: string
                          required:
                            - code
                            - message
                      required:
                        - index
                        - outcome
                required:
                  - counts
                  - results
        '400':
          description: Validation error or atomic rollback
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - validation_error
                          - missing_required_field
                          - bulk_atomic_rollback
                      message:
                        type: string
                      details:
                        type: object
                        additionalProperties:
                          nullable: true
                    required:
                      - code
                      - message
                required:
                  - error
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - unauthorized
                      message:
                        type: string
                      details:
                        type: object
                        additionalProperties:
                          nullable: true
                    required:
                      - code
                      - message
                required:
                  - error
        '403':
          description: Admin required
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - forbidden
                      message:
                        type: string
                      details:
                        type: object
                        additionalProperties:
                          nullable: true
                    required:
                      - code
                      - message
                required:
                  - error
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key or OAuth Token
      description: Pass an API key (marfa_k1_...) or OAuth access token (marfa_at_...)

````