---
title: Message Count API
updatedAt: 2026-09-08T10:03:28.299Z
---

Fetch the complete documentation index at: https://docs.watchers.io/llms.txt

# Message Count API

This function is created for showing how many messages are in the room by providing the roomId.

## REST API

> ⚠️ **Regional endpoints:** Replace `chatbackend.watchers.io` with the endpoint matching your project region. See [Supported Regions](https://docs.watchers.io/docs/supported-regions) for details.
> | Region | Endpoint |
> | :--- | :--- |
> | Europe (default) | `chatbackend.watchers.io` |
> | North America | `chatbackend.us.watchers.io` |
> | South America | `chatbackend.sa.watchers.io` |
> | Asia | `chatbackend.hk.watchers.io` |
> | Africa | `chatbackend.za.watchers.io` |

### **URLs** **[https://chatbackend.watchers.io/message/external/count](https://chatbackend.watchers.io/message/external/count)**

**Parameters:**

| Name         | type              | Description                                        |
| ------------ | ----------------- | -------------------------------------------------- |
| **roomiIds** | string(**Array**) | roomID used in the chat initialisation in your App |
| **apiKey**   | string            | API Key                                            |

**Response Example:**

```json
[{"count":2,"roomId":"1234"},{"count":0,"roomId":"123"}]
```

**usage Example:**

```bash Bash
curl --location --request POST 'https://chatbackend.watchers.io/message/external/count' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'roomIds[]={ROOM ID}' --data-urlencode 'roomIds[]={ROOM ID}' --data-urlencode 'apiKey={API KEY}'
```

## WS Version

You can connect by WebSockets to URLs below and emit event “**listenMessageCount**” with parameters

| Name        | Type          | Description                                                           |
| ----------- | ------------- | --------------------------------------------------------------------- |
| **roomIds** | string(Array) | room id of room which you want to get a last message (Limit 50 rooms) |
| **apiKey**  | string        | your puclic API key                                                   |

And you will receive the events for each room with name “**messageCount**” every 30 seconds

### **Urls** [https://chatbackend.watchers.io](https://chatbackend.watchers.io/)

### Response (WS payload what you will receive)

Our server will send different events for each room every 30 seconds(If you provide 50 room ids you will receive 50 events)

```json
//Event 1

{
    "roomId": "123",
    "count": 2982
}

//Event 2

{
    "roomId": "456",
    "count": 441
}
```

### Usage example

```javascript
const socket3 = io("https://chatbackend.watchers.io", {
  transports: ["websocket"],
  upgrade: false,
});

socket3.on("messageCount", (payload) => {
  console.log(payload);
});

socket3.on("connect", () => {
  socket3.emit("listenMessageCount", {
    roomIds: "<ROOM ID>",
    apiKey: "<API KEY>",
  });
});
```
