> ## 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.

# Query items by field

> Find items by an indexed field instead of by key, within one scope.

The field must have been declared in `indexes` when the collection was created. Querying any other field returns `400 field_not_indexed` — including every field of a collection that was auto-created by its first write, which has no indexes at all.



## OpenAPI

````yaml /openapi.json post /v1/memory/collections/{collection}/query
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}/query:
    post:
      tags:
        - Memory
      summary: Query items by field
      description: >-
        Find items by an indexed field instead of by key, within one scope.


        The field must have been declared in `indexes` when the collection was
        created. Querying any other field returns `400 field_not_indexed` —
        including every field of a collection that was auto-created by its first
        write, which has no indexes at all.
      operationId: queryMemoryItems
      parameters:
        - $ref: '#/components/parameters/MemoryCollectionParam'
        - $ref: '#/components/parameters/MemoryScopeParam'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MemoryItemQueryRequest'
            examples:
              eq:
                summary: Exact match
                value:
                  where:
                    field: status
                    op: eq
                    value: shipped
              between:
                summary: Inclusive range
                value:
                  where:
                    field: total
                    op: between
                    from: 10
                    to: 100
      responses:
        '200':
          description: Matching items.
          content:
            application/json:
              schema:
                type: object
                required:
                  - items
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/MemoryItem'
                  nextCursor:
                    type: string
                    nullable: true
        '400':
          description: >-
            Invalid body or scope, or `field_not_indexed` when the field carries
            no index.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                field_not_indexed:
                  summary: Field has no index
                  value:
                    code: field_not_indexed
                    message: >-
                      Field 'status' is not indexed on this collection. Indexes
                      are declared when the collection is created and cannot be
                      added later.
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Collection not found.
          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
    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'
  schemas:
    MemoryItemQueryRequest:
      type: object
      description: Look items up by an indexed field instead of by key.
      required:
        - where
      properties:
        where:
          type: object
          description: >-
            One condition on one indexed field. `between` bounds are inclusive
            and must be the same type.
          required:
            - field
            - op
          properties:
            field:
              type: string
              example: status
            op:
              type: string
              enum:
                - eq
                - beginsWith
                - between
            value:
              description: >-
                The value to match. Used by `eq` (string, number or boolean) and
                `beginsWith` (string).
            from:
              description: Lower bound, for `between`.
            to:
              description: Upper bound, for `between`.
        limit:
          type: integer
          default: 50
          minimum: 1
          maximum: 100
        cursor:
          type: string
    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

````