# Getting Messages

## Getting array of messages

<mark style="color:blue;">`GET`</mark> `https://direct.revicom.ltd/api/v1/message`

This method allows for getting arrays of message objects that conform filtration parameters.

#### Query Parameters

| Name                   | Type    | Description                                                                                                                                                                        |
| ---------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| page                   | integer | Requested page: By default, 1                                                                                                                                                      |
| per\_page              | integer | Number of messages per page. By default, 100. The limitation: `page * perPage <= 10000` should be satisfied                                                                        |
| sort                   | string  | Sorting                                                                                                                                                                            |
| time\_from             | string  | Low bound of the time of sending in UTC (or receiving the final `unsent` status). Value example: `2020-01-01T00:00:00Z`                                                            |
| time\_to               | string  | Upper bound of the time of sending in UTC (or receiving the final `unsent` status).                                                                                                |
| dispatch\_id           | integer | <p>Dispatch ID<br><em>Multiple parameter</em></p>                                                                                                                                  |
| message\_uuid          | string  | <p>Message ID<br><em>Multiple parameter</em></p>                                                                                                                                   |
| destination            | string  | <p>Phone number<br><em>Multiple parameter</em></p>                                                                                                                                 |
| status                 | string  | <p>Status<br><em>Multiple parameter</em></p>                                                                                                                                       |
| traffic\_center\_id    | integer | <p>Traffic center ID<br><em>Multiple parameter</em></p>                                                                                                                            |
| tags                   | string  | <p>Message tag<br><em>Multiple parameter</em></p>                                                                                                                                  |
| sending\_method        | string  | <p>Sending method<br><em>Multiple parameter</em></p>                                                                                                                               |
| channel\_type          | string  | <p>Channel type<br><em>Multiple parameter</em></p>                                                                                                                                 |
| traffic\_type          | string  | <p>Traffic type<br><em>Multiple parameter</em></p>                                                                                                                                 |
| template\_id           | string  | <p>Template ID</p><p><em>Multiple parameter</em></p>                                                                                                                               |
| content                | string  | String contained in the message text                                                                                                                                               |
| content\_nor           | string  | String not contained in the message content                                                                                                                                        |
| sender\_name           | string  | <p>Sender name</p><p><em>Multiple parameter</em></p>                                                                                                                               |
| cascade\_message\_uuid | string  | Root cascade message ID                                                                                                                                                            |
| root                   | boolean | `true` – only non-cascade and cascade messages of the first step are returned; `false` – only cascade messages are returned starting from the second step;  By default, null       |
| ready\_to\_stop        | boolean | `true` – only ready to stop messages are returned (see Stopping messages)                                                                                                          |
| country\_code          | string  | Subscriber’s country two-letter code according to [ISO-3166](https://www.iso.org/iso-3166-country-codes.html)                                                                      |
| direction              | string  | <p>Message direction; by default, <code>outbound</code></p><p><em>Multiple parameter</em></p>                                                                                      |
| dispatch               | booean  | <p><code>true</code> – only dispatch messages are returned;</p><p><code>false</code> – only single messages are returned.</p><p><em>Applicable for outbound-messages only</em></p> |

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | string | `Basic {TOKEN_1}` |

{% tabs %}
{% tab title="200 " %}

```
{
  "page": 1,
  "perPage": 1,
  "total": 100,
  "items": [
    {
      ... // message object
    }
  ]
}
```

{% endtab %}

{% tab title="401 Invalid token used/authorization header absent" %}
{% tabs %}
{% tab title="4012" %}

```
{
    "error": {
        "code": 4012,
        "msg": "Bad credentials"
    }
}
```

{% endtab %}

{% tab title="4010" %}

```
{
    "error": {
        "code": 4010,
        "msg": "Not Authenticated"
    }
}
```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
This method allows for getting no more than 10,000 messages from one digest. That is, regardless of the total value in the response, paging is possible until the number of 10,000 messages is exceeded.
{% endhint %}

{% hint style="info" %}
To have the option to get inbounds, please, contact a manager.
{% endhint %}

Enumerations:

| Parameter       | Allowed Values                                                                      |
| --------------- | ----------------------------------------------------------------------------------- |
| sort            | <ul><li>sentTime:asc</li><li>sentTime:desc</li></ul>                                |
| status          | [Message statuses​](https://api.direct.revicom.ltd/extra/references#message-states) |
| sending\_method | [Sending methods](https://api.direct.revicom.ltd/extra/references#sending-methods)  |
| channel\_type   | [Channel types](https://api.direct.revicom.ltd/extra/references#channel-types)      |
| traffic\_type   | [Traffic types​](https://api.direct.revicom.ltd/extra/references#traffic-types)     |
| direction       | [Directions](https://api.direct.revicom.ltd/extra/references#directions)            |

## Response object description <a href="#response-object" id="response-object"></a>

| Parameter | Type    | Description                                                            |
| --------- | ------- | ---------------------------------------------------------------------- |
| page      | integer | Requested page number                                                  |
| perPage   | integer | Number of entries per page                                             |
| total     | integer | The total number of the entries found that matched the filter criteria |
| items     | array   | Message objects array (described below)                                |

## Request Example <a href="#example" id="example"></a>

This allows for getting dispatch messages 1 and 2 in the delivered and undelivered statuses, to which this status was assigned in the interval from 2020-11-01 21:00:00 UTC to 2020-11-02 21:00:00 UTC

{% tabs %}
{% tab title="JSON" %}

```
GET https://direct.revicom.ltd/api/v1/message?time_from=2020-11-01T21:00:00Z&time_to=2020-11-02T21:00:00Z&dispatch_id=1&dispatch_id=2&status=delivered&status=undelivered
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
```

{% endtab %}

{% tab title="cURL" %}

```
curl -X GET 'https://direct.revicom.ltd/api/v1/message?time_from=2020-11-01T21:00:00Z&time_to=2020-11-02T21:00:00Z&dispatch_id=1&dispatch_id=2&status=delivered&status=undelivered' \
-H 'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
```

{% endtab %}
{% endtabs %}

## Getting message by uuid

<mark style="color:blue;">`GET`</mark> `https://direct.revicom.ltd/api/v1/message/{message_uuid}`

#### Path Parameters

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| message\_uuid<mark style="color:red;">\*</mark> | string | Message uuid |

#### Headers

| Name                                            | Type   | Description       |
| ----------------------------------------------- | ------ | ----------------- |
| Authorization<mark style="color:red;">\*</mark> | string | `Basic {TOKEN_1}` |

{% tabs %}
{% tab title="200 " %}

```
{
  "createdTime": "2020-01-01T08:00:00Z",
  "channelType": "SMS",
  "sendingMethog": "UI",
  "trafficType": "SERVICE",
  "templateId": 120,
  "dispatchId": 123,
  "dispatchName": "dispatch 1",
  "messageUuid": "9d213ffc-c388-46f5-b42b-01d589d1a815",
  "trafficCenterId": 1,
  "senderName": "testSender",
  "destination": "14085553911",
  "content": "message text",
  "tags": [
    "tag1",
    "tag2"
  ],
  "ttl": 86400,
  "hours": [
    10,
    11,
    12
  ],
  "days": [
    5,
    6
  ],
  "localSendTime": "2021-02-02 15:00:00",
  "localCompletionTime": "2021-02-10 15:00:00",
  "useLocalTime": true,
  "callbackEvents": [
    "sent",
    "delivered"
  ],
  "callbackUrl": "https://url-for-callbacks",
  "totalParts": 1,
  "price": {
    "totalPrice": 2.5,
    "currency": "RUB",
    "invoicedParts": 1,
    "final": false
  },
  "sentTime": "2020-01-01T09:00:00Z",
  "statusTime": "2020-01-01T10:00:00Z",
  "status": "undelivered",
  "cascadeMessageUuid": "9d213ffc-c388-46f5-b42b-01d589d1a814",
  "cascadeStep": 1,
  "errorCode": 7060
}
```

{% endtab %}

{% tab title="401" %}
Invalid token used.

```
{
    "error": {
        "code": 4012,
        "msg": "Bad credentials"
    }
}
```

{% endtab %}

{% tab title="403" %}
Token of wrong type used.

```
{
    "error": {
        "code": 4030,
        "msg": "Access Denied"
    }
}
```

{% endtab %}
{% endtabs %}

## Message object description <a href="#message-object" id="message-object"></a>

| Parameter                  | Type            | Description                                                                                            |
| -------------------------- | --------------- | ------------------------------------------------------------------------------------------------------ |
| createdTime                | string          | Message creation time (UTC)                                                                            |
| channelType                | string          | [Channel type](https://api.direct.revicom.ltd/extra/references#channel-types)                          |
| sendingMethod              | string          | [Sending method](https://api.direct.revicom.ltd/extra/references#sending-methods)                      |
| trafficType                | string          | [Traffic type](https://api.direct.revicom.ltd/extra/references#traffic-types)                          |
| templateId                 | integer         | Template ID (possible for SERVICE and TRANSACT traffic type)                                           |
| dispatchId                 | integer         | Dispatch ID (-1 for single messages)                                                                   |
| dispatchName               | string          | Dispatch name (if exists)                                                                              |
| messageUuid                | string          | Message ID                                                                                             |
| trafficCenterId            | integer         | Traffic partitioning center ID                                                                         |
| senderName                 | string          | Sender name                                                                                            |
| destination                | string          | Subscriber's number                                                                                    |
| direction                  | string          | [Direction](https://api.direct.revicom.ltd/extra/references#directions)                                |
| brand                      | string          | Subscriber's mobile operator                                                                           |
| country                    | string          | Subscriber's country                                                                                   |
| region                     | string          | Subscriber's region                                                                                    |
| content                    | string          | Message text                                                                                           |
| tags                       | array           | Array of tags (if exists)                                                                              |
| ttl                        | integer         | Message ttl                                                                                            |
| hours                      | array (integer) | Allowed hours for sending                                                                              |
| days                       | array (integer) | Allowed days for sending                                                                               |
| localSendTime              | string          | Low bound of the sending time                                                                          |
| localCompletionTime        | string          | Upper bound of the sending time                                                                        |
| useLocalTime               | boolean         | Flag which shows if subscribers local time is used for localSendTime, localCompletionTime, hours, days |
| callbackEvents             | string          | [Callback Events](https://api.direct.revicom.ltd/extra/references#callback-events)                     |
| callbackUrl                | string          | Address to send callback                                                                               |
| totalParts                 | integer         | Number of parts in the message                                                                         |
| price.totalPrice           | number          | Message cost                                                                                           |
| price.currency             | string          | Message currency                                                                                       |
| price.invoicedParts        | integer         | Number of the rated parts                                                                              |
| price.final                | boolean         | Price is final (true) / preliminary (false)                                                            |
| sentTime                   | string          | Sending time (UTC)                                                                                     |
| status                     | string          | [Message status​](https://api.direct.revicom.ltd/extra/references#message-states)                      |
| statusTime                 | string          | Status time (UTC)                                                                                      |
| readStatus                 | string          | [Read status​](https://api.direct.revicom.ltd/extra/references#message-read-states)                    |
| readStatusTime             | string          | Read status time (UTC)                                                                                 |
| specialContent             | object          | Message content                                                                                        |
| specialContent.contentType | string          | Message content type​. For SMS only `text`                                                             |
| specialContent.text        | string          | Message text                                                                                           |
| errorCode                  | integer         | [Error code​](https://api.direct.revicom.ltd/extra/references/error-codes)                             |
| cascadeMessageUuid         | string          | Root cascade message ID                                                                                |
| cascadeStep                | integer         | Cascade step number                                                                                    |
