# Messages

## Get all messages

Get all messages belonging to the specified [Message threads](/connector-api/operations/messagethreads.md#message-thread). Messages can only be returned for message threads you have created. Note this operation uses [Pagination](/connector-api/guidelines/pagination.md) and supports [Portfolio Access Tokens](/connector-api/concepts/multi-property.md).

### Request

`[PlatformAddress]/api/connector/v1/messages/getAll`

```javascript
{
  "ClientToken": "E0D439EE522F44368DC78E1BFB03710C-D24FB11DBE31D4621C4817E028D9E1D",
  "AccessToken": "C66EF7B239D24632943D115EDE9CB810-EA00F8FD8294692C940F6B5A8F9453D",
  "Client": "Sample Client 1.0.0",
  "MessageThreadIds": [
    "7f9325f6-ef44-4911-89a8-ae51010a5aa4",
    "8d02142f-31cf-4115-90bf-ae5200c7a1ba"
  ],
  "CreatedUtc": {
    "StartUtc": "2022-03-03T00:00:00Z",
    "EndUtc": "2022-03-14T00:00:00Z"
  },
  "EnterpriseIds": [
    "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "4d0201db-36f5-428b-8d11-4f0a65e960cc"
  ],
  "Limitation": {
    "Count": 100
  }
}
```

| Property           | Type                                                                 | Contract                     | Description                                                                                                                               |
| ------------------ | -------------------------------------------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `ClientToken`      | string                                                               | required                     | Token identifying the client application.                                                                                                 |
| `AccessToken`      | string                                                               | required                     | Access token of the client application.                                                                                                   |
| `Client`           | string                                                               | required                     | Name and version of the client application.                                                                                               |
| `EnterpriseIds`    | array of string                                                      | optional, max 1000 items     | Unique identifiers of the Enterprises. If not specified, the operation returns data for all enterprises within scope of the Access Token. |
| `MessageThreadIds` | array of string                                                      | required, max 1000 items     | Unique identifiers of `MessageThread`s from where to return messages.                                                                     |
| `CreatedUtc`       | [Time interval](/connector-api/operations/_objects.md#time-interval) | optional, max length 1 month | Interval in which the `Message` was created.                                                                                              |
| `Limitation`       | [Limitation](/connector-api/guidelines/pagination.md#limitation)     | required                     | Limitation on the quantity of data returned and optional Cursor for the starting point of data.                                           |

### Response

```javascript
{
  "Messages": [
    {
      "Id": "4bfe4675-98a9-4428-9ea9-ae5300dbaa93",
      "MessageThreadId": "7f9325f6-ef44-4911-89a8-ae51010a5aa4",
      "Text": "Text of the message",
      "Sender": {
        "Discriminator": "Application",
        "Value": null
      },
      "CreatedUtc": "2022-03-09T13:19:46Z"
    }
  ],
  "Cursor": "7f9325f6-ef44-4911-89a8-ae51010a5aa4"
}
```

| Property   | Type                         | Contract | Description                                                                                                                                                          |
| ---------- | ---------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Messages` | array of [Message](#message) | required | The filtered messages.                                                                                                                                               |
| `Cursor`   | string                       | optional | Unique identifier of the last and hence oldest message returned. This can be used in `Limitation` in a subsequent request to fetch the next batch of older messages. |

#### Message

| Property          | Type              | Contract | Description                                                               |
| ----------------- | ----------------- | -------- | ------------------------------------------------------------------------- |
| `Id`              | string            | required | Unique identifier of the message.                                         |
| `MessageThreadId` | string            | required | Unique identifier of the `MessageThread` to which the message belongs to. |
| `Text`            | string            | required | Text of the message.                                                      |
| `Sender`          | [Sender](#sender) | required | The sender of the message.                                                |
| `CreatedUtc`      | string            | required | Creation date and time of the message in UTC timezone in ISO 8601 format. |

#### Sender

| Property        | Type                                          | Contract | Description                                                                    |
| --------------- | --------------------------------------------- | -------- | ------------------------------------------------------------------------------ |
| `Discriminator` | [Sender discriminator](#sender-discriminator) | required | The sender of the message.                                                     |
| `Value`         | any                                           | optional | Additional information about the sender. Currently not used and always `null`. |

#### Sender discriminator

* `Enterprise` - The message was created by an employee of the enterprise.
* `Application` - The message was created by the third party application.

## Add messages

Add the specified messages to the specified [Message threads](/connector-api/operations/messagethreads.md#message-thread). You can only add messages to message threads that you have created.

### Request

`[PlatformAddress]/api/connector/v1/messages/add`

```javascript
{
  "ClientToken": "E0D439EE522F44368DC78E1BFB03710C-D24FB11DBE31D4621C4817E028D9E1D",
  "AccessToken": "C66EF7B239D24632943D115EDE9CB810-EA00F8FD8294692C940F6B5A8F9453D",
  "Client": "Sample Client 1.0.0",
  "Messages": [
    {
      "MessageThreadId": "7f9325f6-ef44-4911-89a8-ae51010a5aa4",
      "Text": "Text of the message",
      "Identifier": "Message 1"
    }
  ]
}
```

| Property      | Type                                               | Contract                 | Description                                 |
| ------------- | -------------------------------------------------- | ------------------------ | ------------------------------------------- |
| `ClientToken` | string                                             | required                 | Token identifying the client application.   |
| `AccessToken` | string                                             | required                 | Access token of the client application.     |
| `Client`      | string                                             | required                 | Name and version of the client application. |
| `Messages`    | array of [Message parameters](#message-parameters) | required, max 1000 items | Messages to be added.                       |

#### Message parameters

| Property          | Type   | Contract | Description                                                                    |
| ----------------- | ------ | -------- | ------------------------------------------------------------------------------ |
| `MessageThreadId` | string | required | Unique identifier of the `MessageThread` to which the message should be added. |
| `Text`            | string | required | Text of the message.                                                           |
| `Identifier`      | string | optional | Identifier of the message to be created.                                       |

### Response

```javascript
{
  "Messages": [
    {
      "Identifier": "Message 1",
      "Message": {
        "Id": "4bfe4675-98a9-4428-9ea9-ae5300dbaa93",
        "MessageThreadId": "7f9325f6-ef44-4911-89a8-ae51010a5aa4",
        "Text": "Text of the message",
        "Sender": {
          "Discriminator": "Application",
          "Value": null
        },
        "CreatedUtc": "2022-03-09T13:19:46Z"
      }
    }
  ]
}
```

| Property   | Type                                     | Contract | Description                     |
| ---------- | ---------------------------------------- | -------- | ------------------------------- |
| `Messages` | array of [Added message](#added-message) | required | Collection of created messages. |

#### Added message

| Property     | Type                | Contract | Description                                    |
| ------------ | ------------------- | -------- | ---------------------------------------------- |
| `Identifier` | string              | optional | Identifier of the created message.             |
| `Message`    | [Message](#message) | required | Message that was added to the `MessageThread`. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mews.com/connector-api/operations/messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
