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

# Write an item

> Store a JSON document under a key. Creates the collection if it does not exist — with **no indexes**, which `query` then cannot use. Declare indexes with `POST /v1/memory/collections` first if you need them.

This replaces the whole document; it does not merge. Pass `If-Match` with the revision from a previous read to make the write conditional.



## OpenAPI

````yaml /openapi.json put /v1/memory/collections/{collection}/items/{key}
openapi: 3.0.3
info:
  title: Zavu Unified Messaging Layer API
  version: 0.2.0
  description: >
    Unified multi-channel messaging API for Zavu.


    Supported channels:

    - **SMS**: Simple text messages

    - **WhatsApp**: Rich messaging with media, buttons, lists, CTA URL buttons,
    location requests, and templates

    - **Telegram**: Bot messaging with text, media, and interactive elements

    - **Email**: Transactional emails via Amazon SES


    Design goals:

    - Simple `send()` entrypoint for developers

    - Project-level authentication via Bearer token

    - Support for all WhatsApp message types (text, image, video, audio,
    document, sticker, location, contact, buttons, list, cta_url,
    location_request, reaction, template)

    - If a non-text message type is sent, WhatsApp channel is used automatically

    - 24-hour WhatsApp conversation window enforcement

    - Universal `to` field accepts phone numbers (E.164), email addresses, or
    numeric chat IDs (Telegram/Instagram/Messenger)
servers:
  - url: https://api.zavu.dev
security:
  - bearerAuth: []
paths:
  /v1/memory/collections/{collection}/items/{key}:
    put:
      tags:
        - Memory
      summary: Write an item
      description: >-
        Store a JSON document under a key. Creates the collection if it does not
        exist — with **no indexes**, which `query` then cannot use. Declare
        indexes with `POST /v1/memory/collections` first if you need them.


        This replaces the whole document; it does not merge. Pass `If-Match`
        with the revision from a previous read to make the write conditional.
      operationId: putMemoryItem
      parameters:
        - $ref: '#/components/parameters/MemoryCollectionParam'
        - $ref: '#/components/parameters/MemoryItemKeyParam'
        - $ref: '#/components/parameters/MemoryScopeParam'
        - $ref: '#/components/parameters/MemoryIfMatchParam'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MemoryItemPutRequest'
            example:
              value:
                status: shipped
                total: 42.5
      responses:
        '200':
          description: Existing item replaced.
          content:
            application/json:
              schema:
                type: object
                required:
                  - item
                properties:
                  item:
                    $ref: '#/components/schemas/MemoryItem'
        '201':
          description: Item created.
          content:
            application/json:
              schema:
                type: object
                required:
                  - item
                properties:
                  item:
                    $ref: '#/components/schemas/MemoryItem'
        '400':
          description: Invalid key, scope, TTL, or `If-Match`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            `revision_conflict`: the item changed since the revision in
            `If-Match`. Re-read it and retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '413':
          description: >-
            `document_too_large`: the serialized value exceeds 200KB. Memory is
            not a blob store; put media in file storage and keep the URL here.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: The plan's monthly unit quota is spent.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  parameters:
    MemoryCollectionParam:
      name: collection
      in: path
      required: true
      description: Collection name.
      schema:
        type: string
    MemoryItemKeyParam:
      name: key
      in: path
      required: true
      description: 'Item key. 1-255 chars from A-Z a-z 0-9 . _ : @ -'
      schema:
        type: string
    MemoryScopeParam:
      name: scope
      in: query
      required: false
      description: >-
        Which scope to address: `contact:<contactId>`,
        `conversation:<conversationId>`, or omitted for the project scope.


        Note the asymmetry with `POST /v1/memory` and `POST /v1/memory/search`,
        which take the scope in the request BODY as `scope` plus
        `contactId`/`conversationId`. Every other Memory endpoint takes it here.
      schema:
        $ref: '#/components/schemas/MemoryScopeQuery'
    MemoryIfMatchParam:
      name: If-Match
      in: header
      required: false
      description: >-
        Make the write conditional on the item's current revision, as returned
        by a previous read or write (plain `3` or ETag-quoted `"3"`). The write
        is refused with `409 revision_conflict` if the item moved on in between.
        Without it, the write always wins and silently overwrites a concurrent
        one.
      schema:
        type: string
        example: '3'
  schemas:
    MemoryItemPutRequest:
      type: object
      required:
        - value
      properties:
        value:
          description: >-
            The document to store. Any JSON value, max 200KB serialized and 32
            levels deep. This is a whole-document write, not a merge: it
            replaces whatever the key held.
        ttlSeconds:
          type: integer
          description: Overrides the collection's `defaultTtlSeconds` for this item.
          minimum: 60
          maximum: 63072000
    MemoryItem:
      type: object
      description: One JSON document in a collection.
      required:
        - key
        - rev
        - createdAt
        - updatedAt
      properties:
        key:
          type: string
          example: ORD-12345
        value:
          description: The stored JSON. Any JSON value.
          example:
            status: shipped
            total: 42.5
        rev:
          type: integer
          description: >-
            Revision, incremented on every write. Pass it as `If-Match` on a
            later write to make that write conditional.
          example: 3
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        expiresAt:
          type: string
          format: date-time
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          example: invalid_request
        message:
          type: string
          example: Phone number is invalid
        details:
          type: object
          additionalProperties: true
    MemoryScopeQuery:
      type: string
      description: >-
        Scope as a query-string value: `contact:<contactId>`,
        `conversation:<conversationId>`, the literal `project`, or omitted for
        project scope.


        Only the SHAPE of the id is validated, never its existence — the
        partition already carries your project, so an id that matches nothing
        simply addresses an empty scope rather than returning 404.
      example: contact:jd7x2k3m4n5p6q7r8s9t0abc
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````