# Presence A `Presence` object enables a client to query the presence set of a channel over REST. Access it via the `presence` property of a [`Channel`](https://ably.com/docs/pub-sub/api/javascript/rest/channel.md) instance. The REST presence interface is query-only: it retrieves the current members of the presence set and their history. Entering, updating, leaving, and subscribing to presence events require the [realtime SDK's `RealtimePresence`](https://ably.com/docs/pub-sub/api/javascript/realtime/realtime-presence.md) interface. #### Javascript ``` const channel = rest.channels.get('your-channel-name'); const members = await channel.presence.get(); ``` ## Get the presence set `presence.get(params?: RestPresenceParams): Promise>` Retrieve the current members of the presence set for the channel. This method directly queries [Ably's REST presence API](https://ably.com/docs/api/rest-api.md#presence) and returns a [paginated](https://ably.com/docs/pub-sub/api/javascript/rest/rest-client.md#PaginatedResult) set of [`PresenceMessage`](https://ably.com/docs/pub-sub/api/javascript/rest/presence-message.md) objects, one for each member, with metadata such as the member's `clientId`, `connectionId`, action, and any associated data. ### Javascript ``` const members = await channel.presence.get({ limit: 100 }); members.items.forEach((member) => { console.log(member.clientId, member.data); }); ``` ### Parameters The `get()` method takes the following parameters: | Parameter | Required | Description | Type | | --- | --- | --- | --- | | params | Optional | Filter options for the query. |
|
| Property | Required | Description | Type | | --- | --- | --- | --- | | clientId | Optional | Filters the returned members by the [`clientId`](https://ably.com/docs/auth/identified-clients.md) they are identified as. | String | | connectionId | Optional | Filters the returned members by the ID of the [realtime connection](https://ably.com/docs/pub-sub/api/javascript/realtime/connection.md) they entered on. | String | | limit | Optional | An upper limit on the number of members returned. Default: 100. Maximum: 1000. | Number |
### Returns `Promise>` Returns a promise. The promise is fulfilled with a [`PaginatedResult`](https://ably.com/docs/pub-sub/api/javascript/rest/rest-client.md#PaginatedResult) containing an array of [`PresenceMessage`](https://ably.com/docs/pub-sub/api/javascript/rest/presence-message.md) objects representing the current members of the presence set, or rejected with an [`ErrorInfo`](https://ably.com/docs/pub-sub/api/javascript/rest/rest-client.md#errorinfo) object. ## Get presence history `presence.history(params?: RestHistoryParams): Promise>` Get a [paginated](https://ably.com/docs/pub-sub/api/javascript/rest/rest-client.md#PaginatedResult) set of historical presence message events for the channel. If the channel is [configured to persist messages](https://ably.com/docs/storage-history/storage.md), presence message history is available for the duration configured for your account. Otherwise, presence message events are only retained in memory by the Ably service for two minutes. ### Javascript ``` const history = await channel.presence.history({ limit: 50 }); history.items.forEach((member) => { console.log(member.action, member.clientId); }); ``` ### Parameters The `history()` method takes the following parameters: | Parameter | Required | Description | Type | | --- | --- | --- | --- | | params | Optional | Query parameters as specified in the [presence history API documentation](https://ably.com/docs/storage-history/history.md#presence-history). |
|
| Property | Required | Description | Type | | --- | --- | --- | --- | | start | Optional | The time from which presence events are retrieved, as milliseconds since the Unix epoch. Default: the beginning of time. | Number | | end | Optional | The time until which presence events are retrieved, as milliseconds since the Unix epoch. Default: current time. | Number | | direction | Optional | The order of returned presence events. `'backwards'` orders from most recent to oldest; `'forwards'` orders from oldest to most recent. Default: `'backwards'`. | String | | limit | Optional | An upper limit on the number of presence events returned. Default: 100. Maximum: 1000. | Number |
### Returns `Promise>` Returns a promise. The promise is fulfilled with a [`PaginatedResult`](https://ably.com/docs/pub-sub/api/javascript/rest/rest-client.md#PaginatedResult) containing an array of [`PresenceMessage`](https://ably.com/docs/pub-sub/api/javascript/rest/presence-message.md) objects, or rejected with an [`ErrorInfo`](https://ably.com/docs/pub-sub/api/javascript/rest/rest-client.md#errorinfo) object. ## Related Topics - [PresenceMessage](https://ably.com/docs/pub-sub/api/javascript/rest/presence-message.md): API reference for the PresenceMessage type in the Ably Pub/Sub JavaScript REST SDK. ## Documentation Index To discover additional Ably documentation: 1. Fetch [llms.txt](https://ably.com/llms.txt) for the canonical list of available pages. 2. Identify relevant URLs from that index. 3. Fetch target pages as needed. Avoid using assumed or outdated documentation paths.