# List

To list the chat messages for a concrete room you need to execute a **GET** request against the **/rooms/:id/chat** endpoint.&#x20;

{% hint style="info" %}
Use the **session\_id** argument if you want to list messages written in a concrete session.\
<https://api.digitalsamba.com/api/v1/rooms/c39d7c40-7ff7-4faa-b06f-698a639a9523/chat?**session\\_id**=16e44502-dae5-41f9-b095-e41bf6ac2d1d>
{% endhint %}

Since potentially there could be thousands of messages, pagination is supported with **limit**, **order** and **after** arguments. Read about [pagination](https://docs.digitalsamba.com/reference/rest-api/pagination) to learn the details of it. By default maximum 100 chat messages will be returned in the response.

{% hint style="info" %}
Only **public** chat messages are retrievable. Private (1-to-1) chat is not persisted and cannot be retrieved through the API.
{% endhint %}

#### Request

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```bash
curl --request GET \
  --url https://api.digitalsamba.com/api/v1/rooms/c39d7c40-7ff7-4faa-b06f-698a639a9523/chat \
  --user YOUR_TEAM_ID:YOUR_DEVELOPER_KEY
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}

```java
import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.Base64;
import java.util.Map;

String TEAM_ID = "YOUR_TEAM_ID";
String DEVELOPER_KEY = "YOUR_DEVELOPER_KEY";
String authorizationHeader = "Bearer " + Base64.getEncoder().encodeToString((TEAM_ID + ":" + DEVELOPER_KEY).getBytes());
//Put your room id or friendly_url (name) here - this value is just an example
String roomId = "c39d7c40-7ff7-4faa-b06f-698a639a9523";

HttpRequest request = HttpRequest.newBuilder()
  .GET()
  .uri(new URI("https://api.digitalsamba.com/api/v1/rooms/" + roomId + "/chat"))
  .header("Authorization", authorizationHeader)
  .build();

HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

System.out.println("Status code: " + response.statusCode());
System.out.println("Body: " + response.body());
```

{% endtab %}
{% endtabs %}

#### Response (200 OK)

```json
{
    "total_count": 6124,
    "data": [
        {
            "id": "87664473-9064-4179-935e-ce78af687bef",
            "message": "Hello!",
            "participant_id": "77836281-486c-4d49-ba07-c66c87452256",
            "external_participant_id": "ABCDEF",
            "participant_name": "Cillian Doe",
            "created_at": "2024-03-13T14:10:22Z"
        },
        {
            "id": "eccf427e-9fa3-481d-912b-f35c15473a46",
            "message": "dfdsf",
            "participant_id": "722d9849-e94f-4cba-903a-9e8e61d8d861",
            "participant_name": "John Smith",
            "created_at": "2024-03-09T11:32:30Z"
        },
        ...............98 more chat messages...............
    ]
} 
```

{% hint style="info" %}
The **total\_count** is the total amount of chat messages in the room. It is **NOT** the amount of chat messages in the current page returned in the **data** array. In the above example you have 6124 messages in total, but in the data array there will be maximum 100 chat messages (the default limit argument value).
{% endhint %}
