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

# Fetch many chat messages

> Stateless fetcher for conversation messages — no Redux, no socket

export const SpaceReputationParams = ({variant = "context", field = "path"}) => {
  const isUser = variant === "user";
  return <>
      <ParamField {...{
    [field]: "spaceReputation",
    type: "object"
  }}>
        Opt-in. Adds a <code>spaceReputation</code> number to each returned user,
        scoped to a single space. Requires the <code>reputation</code> bundle.
        The <code>reputation</code> total is always present regardless;{" "}
        <code>spaceReputation</code> is purely additive and only appears when you
        pass this object. <strong>This object is the primary form</strong> — it
        replaces the deprecated flat props below. See the{" "}
        <a href="/v8/data-models/reputation">Reputation data model</a> for the
        full contract.

        <Expandable title="spaceReputation">
          {isUser ? <ParamField name="spaceId" type="string | &quot;none&quot;" required>
              Which bucket to read. A space <strong><code>&lt;uuid&gt;</code></strong> reads that
              space's bucket; <strong><code>"none"</code></strong> reads the
              project-general (space-less) bucket.{" "}
              <strong><code>"context"</code> is rejected (400)</strong> on this
              endpoint — there is no space context to derive. The empty string
              and the legacy <code>general</code> / <code>null</code> aliases are
              also rejected. Missing buckets read as <code>0</code>.
            </ParamField> : <ParamField name="spaceId" type="string | &quot;none&quot; | &quot;context&quot;" required>
              Which bucket to read. One of: a space <strong><code>&lt;uuid&gt;</code></strong>{" "}
              (that space's bucket), <strong><code>"none"</code></strong> (the
              project-general, space-less bucket), or{" "}
              <strong><code>"context"</code></strong> (the space derived from the
              request context — resolved per-row on lists, or the single space on
              member/team/conversation surfaces). The empty string and the legacy{" "}
              <code>general</code> / <code>null</code> aliases are rejected (400).
              Missing buckets read as <code>0</code>.
            </ParamField>}
          <ParamField name="includeDescendants" type="boolean">
            Only honored when <code>spaceId</code> is an explicit space <code>&lt;uuid&gt;</code>.
            When <code>true</code>, <code>spaceReputation</code> is the{" "}
            <strong>subtree sum</strong> — the named space plus all of its
            descendant spaces (the root space's own bucket included). Ignored for{" "}
            <code>"none"</code>; not allowed with <code>"context"</code>.
          </ParamField>
        </Expandable>
      </ParamField>

      {isUser ? <ParamField {...{
    [field]: "spaceReputationId",
    type: "string",
    deprecated: true
  }}>
          <strong>Deprecated</strong> — use the <code>spaceReputation</code>{" "}
          object instead. The flat form of <code>spaceReputation.spaceId</code>.
          Still accepted (the object wins if both are passed); removal is a later
          major version. Accepts a space <code>&lt;uuid&gt;</code> or <code>"none"</code> only —{" "}
          <code>"context"</code> is rejected (400) on this endpoint.
        </ParamField> : <ParamField {...{
    [field]: "spaceReputationId",
    type: "string",
    deprecated: true
  }}>
          <strong>Deprecated</strong> — use the <code>spaceReputation</code>{" "}
          object instead. The flat form of <code>spaceReputation.spaceId</code>.
          Still accepted (the object wins if both are passed); removal is a later
          major version. Accepts a space <code>&lt;uuid&gt;</code>, <code>"none"</code>, or{" "}
          <code>"context"</code>.
        </ParamField>}

      <ParamField {...{
    [field]: "spaceReputationDescendants",
    type: "boolean",
    deprecated: true
  }}>
        <strong>Deprecated</strong> — use{" "}
        <code>spaceReputation.includeDescendants</code> instead. The flat form,
        only honored alongside an explicit <code>spaceReputationId</code> <code>&lt;uuid&gt;</code>.
      </ParamField>
    </>;
};

## Overview

`useFetchManyChatMessages` returns a function that fetches a single page of conversation messages and resolves to the raw response. It stores nothing — no Redux, no socket subscription — so you own the resulting state.

This is the low-level fetcher shared by [`useLiveChatMessages`](/v8/hooks/chat/messages/use-live-chat-messages) (the live store-backed view) and [`useFetchManyChatMessagesWrapper`](/v8/hooks/chat/messages/use-fetch-many-chat-messages-wrapper) (a batteries-included paginated list). Use it directly when you need full control; most apps will prefer the wrapper.

<Note>Because results never enter the live store, this is the right tool for **filtered** or read-only queries (e.g. only messages that have replies) that should not be polluted by live socket traffic. It is a point-in-time query — call it again to refresh.</Note>

## Usage Example

```tsx theme={null}
import { useFetchManyChatMessages } from "@sublay/react-js";
import { useState, useEffect } from "react";

function MessagesWithReplies({ conversationId }: { conversationId: string }) {
  const fetchMessages = useFetchManyChatMessages();
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    fetchMessages({ conversationId, filters: { hasReplies: true } }).then((res) =>
      setMessages(res.messages)
    );
  }, [conversationId]);

  return (
    <ul>
      {messages.map((m) => <li key={m.id}>{m.content}</li>)}
    </ul>
  );
}
```

## Parameters

<ParamField path="conversationId" type="string" required>
  The ID of the conversation to query.
</ParamField>

<ParamField path="parentId" type="string | null">
  Restrict to thread replies of this message.
</ParamField>

<ParamField path="before" type="string | null">
  Keyset cursor (ISO timestamp): messages created before this. Mutually exclusive with `after`.
</ParamField>

<ParamField path="after" type="string | null">
  Keyset cursor (ISO timestamp): messages created after this. Mutually exclusive with `before`.
</ParamField>

<ParamField path="limit" type="number">
  Page size (1–100). Defaults to `50`.
</ParamField>

<ParamField path="sort" type="&#x22;asc&#x22; | &#x22;desc&#x22;">
  Sort by creation time.
</ParamField>

<ParamField path="includeFiles" type="boolean">
  When `true`, the server populates the `files` field on each message.
</ParamField>

<ParamField path="includeGrants" type="boolean">
  When `true`, each message carries its [reputation-grant summary](/v8/data-models/reputation-grant#grantsummary) at `message.grants` — `{ total, count, viewerTotal }` over positive grants. Populated by the `reputation` bundle; on a project without it the summary comes back zero-filled rather than missing.
</ParamField>

<SpaceReputationParams variant="context" field="path" />

<ParamField path="filters" type="MessageFilters">
  Optional filters. `filters.hasReplies` (boolean): when `true`, returns only messages that have thread replies (`threadReplyCount > 0`); when `false`, only messages with none. Filters by thread replies, not quotings.

  <Note>Threads are one level deep, so `hasReplies: true` together with `parentId` always returns an empty list — the response's `notice` field explains why.</Note>
</ParamField>

## Returns

A `Promise` resolving to:

<ResponseField name="messages" type="ChatMessage[]">
  Messages for the requested page. When `spaceReputation` is requested, each embedded sender carries an added `spaceReputation` number. See [ChatMessage](/v8/data-models/chat-message) and [Reputation](/v8/data-models/reputation).
</ResponseField>

<ResponseField name="hasMore" type="boolean">
  Whether more messages exist in the requested direction.
</ResponseField>

<ResponseField name="oldestCreatedAt" type="string | null">
  ISO timestamp of the oldest message in this page; `null` if empty.
</ResponseField>

<ResponseField name="newestCreatedAt" type="string | null">
  ISO timestamp of the newest message in this page; `null` if empty.
</ResponseField>

<ResponseField name="notice" type="string">
  Present only when a filter combination can't return results — e.g. `hasReplies: true` together with `parentId`. Explains why the list is empty.
</ResponseField>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.