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

# Lookup docs by ID with Legacy QL

> Retrieve a single document by its unique identifier. This is the most efficient way to fetch a specific document when you know its ID.

<Warning>
  This is a legacy endpoint that uses the [Legacy Query Language](/dql/query-syntax-legacy).

  To use [DQL](/dql), the current Ditto query language, consider using the [execute](./post-storeexecute) endpoint.
</Warning>


## OpenAPI

````yaml post /store/findbyid
openapi: 3.0.3
info:
  title: Ditto HTTP RPC API
  version: 4.0.0
  description: >-
    The Ditto HTTP RPC API provides a RESTful interface for interacting with
    Ditto's distributed data store. It enables you to query, insert, update and
    delete data across your Ditto network while maintaining strong consistency
    guarantees.
servers:
  - url: '{base_url}/api/v4'
    description: >-
      The Ditto Big Peer acts as a central synchronization point and data store
      in your Ditto network. It coordinates data replication between peers and
      provides a consistent view of your data.
    variables:
      base_url:
        default: https://REPLACE_WITH_MY_APP_ID.cloud.ditto.live
        description: >-
          Your unique Ditto application endpoint URL, found in the Ditto Portal
          under Application Settings. Replace REPLACE_WITH_MY_APP_ID with your
          actual app ID.
security:
  - api_key_or_jwt_token: []
externalDocs:
  url: https://docs.ditto.live/http/installation/
  description: >-
    For more detailed instructions on how to use this API and the Ditto SDK,
    please see the documentation.
paths:
  /store/findbyid:
    post:
      description: >-
        Retrieve a single document by its unique identifier. This is the most
        efficient way to fetch a specific document when you know its ID.
      operationId: find_by_id_endpoint
      parameters:
        - name: X-DITTO-TXN-ID
          in: header
          description: >-
            Optional transaction ID for ensuring read consistency. The operation
            will only proceed if the Big Peer's transaction ID is at least this
            value, preventing reads of stale data.
          required: false
          deprecated: false
          schema:
            type: integer
            format: int64
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FindByIdRequest'
        required: true
      responses:
        '200':
          description: >-
            The document was found and retrieved successfully. Returns the
            document data along with the transaction ID of the read operation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FindByIdResponse'
            application/cbor:
              schema:
                $ref: '#/components/schemas/FindByIdResponse'
        '400':
          description: >-
            The request was invalid. This could be due to an invalid ID format,
            unknown collection, or other parameter validation failures. Check
            the error message for specific details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RpcError'
            application/cbor:
              schema:
                $ref: '#/components/schemas/RpcError'
        '401':
          description: >-
            Authentication failed. Ensure you're providing a valid API key or
            JWT token with appropriate read permissions for the requested
            collection.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RpcError'
            application/cbor:
              schema:
                $ref: '#/components/schemas/RpcError'
        '500':
          description: >-
            An unexpected server error occurred. This could be due to resource
            constraints or internal errors. The request may succeed if retried
            after a brief delay.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RpcError'
            application/cbor:
              schema:
                $ref: '#/components/schemas/RpcError'
      deprecated: false
components:
  schemas:
    FindByIdRequest:
      type: object
      description: >-
        Request parameters for retrieving a specific document by its ID. This is
        the most efficient way to fetch a single document when you know its
        identifier.
      required:
        - collection
        - id
      properties:
        collection:
          type: string
          description: The name of the collection containing the document
        formatAttachment:
          type: boolean
          default: false
          description: >-
            When true, any attachment fields will be formatted for easier
            consumption
        id:
          $ref: '#/components/schemas/AnyValue'
          description: The unique identifier of the document to retrieve
        serializedAs:
          $ref: '#/components/schemas/SerializedAs'
          description: Controls how the document data is serialized in the response
      example:
        collection: people
        id: abc123
    FindByIdResponse:
      allOf:
        - $ref: '#/components/schemas/Document'
        - type: object
          properties:
            txnId:
              type: integer
              format: int64
              description: >-
                The transaction ID at which this document was retrieved, useful
                for consistency tracking
    RpcError:
      type: object
      description: Error response returned when an API request fails
      required:
        - message
      properties:
        message:
          type: string
          description: Human-readable description of what went wrong
      example:
        message: Some kind of human readable description of the error
    AnyValue: {}
    SerializedAs:
      type: string
      description: Controls how document values are serialized in responses
      default: latestValues
      enum:
        - latestValues
        - latestValuesAndTypes
    Document:
      type: object
      description: >-
        Represents a document in the Ditto store. Documents are schema-free and
        can contain nested fields of various CRDT types for conflict-free
        replication.
      required:
        - id
        - fields
      properties:
        fields:
          $ref: '#/components/schemas/AnyValue'
          description: >-
            The document's content, which can include any valid JSON data types
            and special Ditto CRDT types
        id:
          $ref: '#/components/schemas/AnyValue'
          description: The unique identifier for this document within its collection
  securitySchemes:
    api_key_or_jwt_token:
      type: http
      scheme: bearer
      bearerFormat: API Key or JWT
      description: >-
        Authentication using either an API key or JWT token in the Authorization
        header

````