# Sessions API

URL: https://developers.cuedesk.com/api/sessions_api

> Retrieve the messages of a session with the Sessions API.

<Callout type="error">
The structures used in this API are **`NOT A GUARANTEE`** and will be removed no later than 31 January 2024.
</Callout>

## Retrieve Session Messages [#retrieve-session-messages]

Retrieve a list of messages for a specific session.

## Endpoint [#endpoint]
```text
GET 
https://api.cuedesk.com/v1/sessions/{sessionId}/messages?limit=20&offset=0
Content-Type: application/json

- Authorization: Bearer token
- {sessionId} (UUID): The UUID of the session.

- limit (integer, default: 20): The maximum number of messages to retrieve.
- offset (integer, default: 0): The starting index of the messages to retrieve.
```

## Sample Response (With Text and Buttons) [#sample-response-with-text-and-buttons]

```json
{
  "data": [
    {
      "uuid": "e8dbf48f-dc8a-4a2c-8f93-72a9dcf5aeed",
      "from": "27721233221",
      "to": "1234121241124",
      "status": "inbound",
      "messageType": "text",
      "content": {
        "text": "hello"
      },
      "error": null,
      "createdAt": "2023-01-01T13:00:00Z",
      "updatedAt": "2023-01-01T13:00:00Z"
    },
    {
      "uuid": "4a6a26c5-5a3e-47f6-b3af-9834c2f1b0e9",
      "from": "1234121241124",
      "to": "27721233221",
      "status": "read",
      "messageType": "button",
      "content": {
        "header": {
          "type": "text",
          "value": "Welcome",
          "filename": null
        },
        "body": "Hello there, we're here to help!",
        "footer": "Please select an option",
        "buttons": [
          {
            "id": "ePOo3AMi5BNnTTpCMioEQ",
            "title": "Log a claim"
          },
          {
            "id": "GExFo60h5e0Ta2hrP0A_X",
            "title": "Manage my policy"
          }
        ]
      },
      "error": null,
      "createdAt": "2023-01-01T13:01:00Z",
      "updatedAt": "2023-01-01T13:01:00Z"
    },
    {
      "uuid": "ee01ccd2-49d4-4193-a4d5-44ee32a399b5",
      "from": "27721233221",
      "to": "1234121241124",
      "status": "inbound",
      "messageType": "reply",
      "content": {
        "id": "ePOo3AMi5BNnTTpCMioEQ",
        "title": "Log a claim",
        "description": null
      },
      "error": null,
      "createdAt": "2023-01-01T13:02:00Z",
      "updatedAt": "2023-01-01T13:02:00Z"
    },
    {
      "uuid": "376eab88-6b11-4e09-9130-eb5f6b8e10ae",
      "from": "1234121241124",
      "to": "27721233221",
      "status": "delivered",
      "messageType": "text",
      "content": {
        "text": "Thank you for your response. An agent will be with you shortly."
      },
      "error": null,
      "createdAt": "2023-01-01T13:03:00Z",
      "updatedAt": "2023-01-01T13:03:00Z"
    }
  ],
  "total": 15
}
```


### Sample Response (With Media) [#sample-response-with-media]
```json
{
  "data": [
    {
      "uuid": "e8dbf48f-dc8a-4a2c-8f93-72a9dcf5aeed",
      "from": "27721233221",
      "to": "1234121241124",
      "status": "inbound",
      "messageType": "text",
      "content": {
        "text": "hello"
      },
      "error": null,
      "createdAt": "2023-01-01T13:00:00Z",
      "updatedAt": "2023-01-01T13:00:00Z"
    },
    {
      "uuid": "f9a052c7-7a8f-4d71-b722-bd0a6ebf3db5",
      "from": "1234121241124",
      "to": "27721233221",
      "status": "read",
      "messageType": "video",
      "content": {
        "url": "https://media.cuedesk.com/...",
        "caption": "sample video caption"
      },
      "error": null,
      "createdAt": "2023-01-01T13:02:00Z",
      "updatedAt": "2023-01-01T13:02:00Z"
    },
    {
      "uuid": "376eab88-6b11-4e09-9130-eb5f6b8e10ae",
      "from": "1234121241124",
      "to": "27721233221",
      "status": "delivered",
      "messageType": "image",
      "content": {
        "url": "https://media.cuedesk.com/...",
        "caption": "sample image caption"
      },
      "error": null,
      "createdAt": "2023-01-01T13:03:00Z",
      "updatedAt": "2023-01-01T13:03:00Z"
    }
  ],
  "total": 10
}

```


### Sample Response (With Option List and User Reply) [#sample-response-with-option-list-and-user-reply]

```json

{
  "data": [
    {
      "uuid": "376eab88-6b11-4e09-9130-eb5f6b8e10ae",
      "from": "1234121241124",
      "to": "27721233221",
      "status": "inbound",
      "messageType": "text",
      "content": {
        "text":"Hello"
      },
      "error": null,
      "createdAt": "2023-01-01T13:01:00Z",
      "updatedAt": "2023-01-01T13:01:00Z"
    },
    {
      "uuid": "f9a052c7-7a8f-4d71-b722-bd0a6ebf3db5",
      "from": "1234121241124",
      "to": "27721233221",
      "status": "read",
      "messageType": "list",
      "content": {
        "header": {
          "type": "text",
          "value": "Incident Report",
          "filename": null
        },
        "body": "We notice that an emergency signal was triggered by your vehicle. Please can you select the most appropriate option:",
        "footer": "MPL",
        "sections": [
          {
            "title": "List Header :)",
            "items": [
              {
                "id": "4sQk7stqygWyMjhvCYn19",
                "title": "Pothole",
                "description": "I have driven over a speedbump"
              },
              {
                "id": "5JpI769pdnWuzTCIPnI3_",
                "title": "Speedbump",
                "description": "I have driven over a speedbump"
              },
              {
                "id": "rOtGnAa-9pR-sN5mRu0b5",
                "title": "Harsh Breaking",
                "description": "I had to brake harshly"
              },
              {
                "id": "PrstdvYLnwBGCsSHsk1hV",
                "title": "Curb Impact",
                "description": "I have hit a curb"
              },
              {
                "id": "XMtIezL8Dbr9FNNxhQtYV",
                "title": "Not Sure",
                "description": "I am unsure what triggered the emergency signal"
              }
            ]
          }
        ]
      },
      "error": null,
      "createdAt": "2023-01-01T13:02:00Z",
      "updatedAt": "2023-01-01T13:02:00Z"
    },
    {
      "uuid": "e8dbf48f-dc8a-4a2c-8f93-72a9dcf5aeed",
      "from": "27721233221",
      "to": "1234121241124",
      "status": "inbound",
      "messageType": "reply",
      "content": {
        "id": "rOtGnAa-9pR-sN5mRu0b5",
        "title": "Harsh Breaking",
        "description": "I had to brake harshly"
      },
      "error": null,
      "createdAt": "2023-01-01T13:03:00Z",
      "updatedAt": "2023-01-01T13:03:00Z"
    },
    {
      "uuid": "376eab88-6b11-4e09-9130-eb5f6b8e10ae",
      "from": "1234121241124",
      "to": "27721233221",
      "status": "read",
      "messageType": "text",
      "content": {
        "text":"Thank you for your response. An agent will be with you shortly."
      },
      "error": null,
      "createdAt": "2023-01-01T13:04:00Z",
      "updatedAt": "2023-01-01T13:04:00Z"
    }
  ],
  "total": 12
}

```

## Response Parameters [#response-parameters]
<table>
    <tr>
        <td><strong>Attribute</strong></td>
        <td><strong>Type</strong></td>
        <td><strong>Description</strong></td>
    </tr>
    <tr>
        <td><code>uuid</code></td>
        <td>UUID</td>
        <td>The unique identifier of the message.</td>
    </tr>
    <tr>
        <td><code>from</code></td>
        <td>string</td>
        <td>The sender of the message.</td>
    </tr>
    <tr>
        <td><code>to</code></td>
        <td>string</td>
        <td>The recipient of the message.</td>
    </tr>
    <tr>
        <td><code>status</code></td>
        <td>string</td>
        <td>The status of the message (e.g., "inbound | read | delivered | sent").</td>
    </tr>
    <tr>
        <td><code>messageType</code></td>
        <td>string</td>
        <td>The type of the message (e.g., "text | button | image").</td>
    </tr>
    <tr>
        <td><code>content</code></td>
        <td>object</td>
        <td>The raw content of the message.</td>
    </tr>
    <tr>
        <td><code>error</code></td>
        <td>string</td>
        <td>Any error associated with the message.</td>
    </tr>
    <tr>
        <td><code>createdAt</code></td>
        <td>string</td>
        <td>The timestamp when the message was created.</td>
    </tr>
    <tr>
        <td><code>updatedAt</code></td>
        <td>string</td>
        <td>The timestamp when the message was last updated.</td>
    </tr>
    <tr>
        <td><code>total</code></td>
        <td>integer</td>
        <td>The total number of messages available.</td>
    </tr>
</table>

## Error Response: [#error-response]

```json
{
  "type": "string",
  "title": "error title",
  "status": 500,
  "instance": "/v1/sessions/{sessionId}/messages"
}
```

<table>
    <tr>
        <td><strong>Attribute</strong></td>
        <td><strong>Type</strong></td>
        <td><strong>Description</strong></td>
    </tr>
    <tr>
        <td><code>type</code></td>
        <td>string</td>
        <td>The type of the error response.</td>
    </tr>
    <tr>
        <td><code>title</code></td>
        <td>string</td>
        <td>The title or description of the error.</td>
    </tr>
    <tr>
        <td><code>status</code></td>
        <td>integer</td>
        <td>The HTTP status code of the error response.</td>
    </tr>
    <tr>
        <td><code>instance</code></td>
        <td>string</td>
        <td>The instance or URL that caused the error.</td>
    </tr>
</table>

<Callout type="error">
The structures used in this API are **`NOT A GUARANTEE`** and will be removed no later than 31 January 2024.
</Callout>
