> ## 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 connections by user ID

> Fetch accepted connections for any user by their ID

## Overview

Returns a function that fetches the paginated list of accepted connections for any user, identified by `userId`. Authentication is optional — the endpoint works without a token. When the caller is signed in, any user with a block between them and the caller, in either direction, is excluded from the results. Block filtering requires the `moderation` bundle.

For fetching your own connections, see `useFetchConnections`.

## Usage Example

```tsx theme={null}
import { useFetchConnectionsByUserId } from "@sublay/react-js";

function UserConnections({ userId }: { userId: string }) {
  const fetchConnectionsByUserId = useFetchConnectionsByUserId();
  const [connections, setConnections] = useState([]);

  useEffect(() => {
    fetchConnectionsByUserId({ userId, page: 1 }).then((res) => {
      setConnections(res.data);
    });
  }, [userId]);

  return (
    <ul>
      {connections.map(({ id, connectedUser }) => (
        <li key={id}>{connectedUser.name}</li>
      ))}
    </ul>
  );
}
```

## Parameters

The hook returns a function. That function accepts:

**userId** `string` *required*

The ID of the user whose connections to fetch.

**page** `number`

Page number to fetch. Defaults to `1`.

**limit** `number`

Number of results per page. Defaults to `20`.

**query** `string`

Optional search term. Filters the list to connections whose connected user's username or name contains this text (case-insensitive). When omitted, no filtering is applied.

**searchFields** `string`

Restricts which field `query` matches against — `username` or `name`. When omitted, `query` matches either field.

**spaceReputation** `object`

Opt-in. Adds a `spaceReputation` number to each returned user,
scoped to a single space. Requires the `reputation` bundle.
The `reputation` total is always present regardless;
`spaceReputation` is purely additive and only appears when you
pass this object. **This object is the primary form** — it
replaces the deprecated flat props below. See the
[Reputation data model](https://docs.sublay.io/v7/data-models/reputation.md) for the
full contract.

**spaceReputation**

Which bucket to read. A space **`<uuid>`** reads that
space's bucket; **`"none"`** reads the
project-general (space-less) bucket.
**`"context"` is rejected (400)** on this
endpoint — there is no space context to derive. The empty string
and the legacy `general` / `null` aliases are
also rejected. Missing buckets read as `0`.
Only honored when `spaceId` is an explicit space `<uuid>`.
When `true`, `spaceReputation` is the
**subtree sum** — the named space plus all of its
descendant spaces (the root space's own bucket included). Ignored for
`"none"`; not allowed with `"context"`.

**spaceReputationId** `string` *deprecated*

**Deprecated** — use the `spaceReputation`
object instead. The flat form of `spaceReputation.spaceId`.
Still accepted (the object wins if both are passed); removal is a later
major version. Accepts a space `<uuid>` or `"none"` only —
`"context"` is rejected (400) on this endpoint.

**spaceReputationDescendants** `boolean` *deprecated*

**Deprecated** — use
`spaceReputation.includeDescendants` instead. The flat form,
only honored alongside an explicit `spaceReputationId` `<uuid>`.

## Returns

Returns a `PaginatedResponse` containing an array of established connections:

**data** `EstablishedConnection[]`

Array of accepted connection entries.

**EstablishedConnection properties**

**id** `string`

ID of the connection record.

**connectedUser** `User`

The other user's profile. When `spaceReputation` is requested, it carries an added `spaceReputation` number. See [User data model](https://docs.sublay.io/v7/data-models/user.md) and [Reputation](https://docs.sublay.io/v7/data-models/reputation.md).

**connectedAt** `string`

ISO timestamp when the connection was established.

**pagination** `object`

Pagination metadata including `page`, `pageSize`, `totalPages`, `totalItems`, and `hasMore`.

## Related

* [useFetchConnections](https://docs.sublay.io/v7/hooks/connections/use-fetch-connections.md) — fetch the current user's own connections
* [useFetchConnectionsCountByUserId](https://docs.sublay.io/v7/hooks/connections/use-fetch-connections-count-by-user-id.md) — get count for any user


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