> For the complete documentation index, see [llms.txt](https://api.direct.revicom.ltd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.direct.revicom.ltd/messages/vk-sending.md).

# Sending VK

## Sending VK

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

The method allows for sending an array of single messages **(1 to 1,000)**

#### Headers

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

#### Request Body

| Name                                          | Type    | Description                                                                                                                                                                                                                                                                                        |
| --------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| channelType<mark style="color:red;">\*</mark> | string  | Sending channel (`VK`)                                                                                                                                                                                                                                                                             |
| senderName<mark style="color:red;">\*</mark>  | string  | Sender name. Any non-empty string is alliwed                                                                                                                                                                                                                                                       |
| destination<mark style="color:red;">\*</mark> | string  | Subscriber number                                                                                                                                                                                                                                                                                  |
| content<mark style="color:red;">\*</mark>     | string  | Message text; UTF-8 encoded string without Byte Order Mark. 1 to 2048 characters                                                                                                                                                                                                                   |
| tags                                          | array   | Message tags (array of strings). Each tag must match the expression `^\w+$` (any case letters, numbers and underscore "\_" are allowed)                                                                                                                                                            |
| useLocalTime                                  | boolean | <p>Flag responsible for the time zone in which the message will be sent:<br><strong><code>true</code></strong> – sending in the subscriber time zone<br><strong><code>false</code></strong> – sending by Moscow time<br><em>By default, true</em></p>                                              |
| localSendTime                                 | string  | <p>Low bound for the allowed time to send a message (subject to <code>useLocalTime</code>)<br>Date in the format '<code>YYYY-MM-DD hh:mm:ss</code>' in the range from (current UTC time – 12 hours) to (current UTC time + 7 days)<br><em>By default the message will be sent immediately</em></p> |
| localCompletionTime                           | string  | Upper bound for the allowed time to send a message (subject to `useLocalTime`) in the range from `localSendTime` to (current UTC time + 70 days)                                                                                                                                                   |
| ttl                                           | integer | <p>Message lifetime in seconds. After the ttl expires, the final status is set to the message<br><code>60 ≤ ttl ≤ 86400</code></p>                                                                                                                                                                 |
| hours                                         | array   | Valid sending hours (array of numbers). Integers from 0 to 23 can be transmitted in the array, each corresponding to the hour interval allowed for sending, subject to `useLocalTime;` the values must be unique.                                                                                  |
| days                                          | array   | Valid sending days (array of numbers). Integers from 1 (Mon) to 7 (Sun) can be transmitted in the array, each corresponding to the week day allowed for sending; the values must be unique.                                                                                                        |
| shortUrl                                      | boolean | <p>Flag responsible for shortening links in the message:<br><code>true</code>- links in the text of the message will be shortened<br>By default, <code>false</code></p>                                                                                                                            |
| callbackUrl                                   | string  | Address to send callback                                                                                                                                                                                                                                                                           |
| callbackEvents                                | array   | Events to send callback (an array of strings). If there is `callbackUrl` and no `callbackEvents` in the request, a callback will be sent on the event `delivered`                                                                                                                                  |

{% tabs %}
{% tab title="200" %}
If the request is successful, a response is returned that lists the message IDs and result codes. With errors = false, all submitted messages are guaranteed to have been successfully generated.

```
{
  "errors": false,
  "items": [
    {
      "messageUuid": "063474ec-a34f-4558-90c5-984395000004",
      "code": 201
    },
    {
      "messageUuid": "063564ec-a34f-4558-90c5-984395000005",
      "code": 201
    }
  ]
}
```

{% endtab %}

{% tab title="401" %}
Invalid token used/authorization header missing.

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

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

{% endtab %}

{% tab title="4010" %}

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

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

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

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

{% endtab %}

{% tab title="422" %}
The request body contains invalid parameters or the maximum number of objects is exceeded.

```
{
    "error": {
        "code": 4220,
        "msg": "Max count of messages is 1000"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Local send time is less than minimal {minLocalSendTime}"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Local send time is greater than minimal {maxLocalSendTime}"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Local completion time is less than minimal {minLocalCompletionTime}"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Local completion time is greater than maximal {maxLocalCompletionTime}"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "No active sender name: ({channelType}, {senderName})"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Invalid msisdn"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Blank content"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Invalid tags: {tags}"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4220,
        "msg": "Invalid TTL {ttl}"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4222,
        "msg": "Invalid hours: {hours}"
    }
}
-----------------------------------------------------------------------------
{
    "error": {
        "code": 4223,
        "msg": "Invalid days: {days}"
    }
}
```

{% endtab %}

{% tab title="503 " %}

```
{
    "error": {
        "code": 5030,
        "msg": "Url shortener is unavailable"
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Recommended minimum timeout: 70 seconds
{% endhint %}

{% hint style="warning" %}
To set up the link shortening functionality, you need to contact customer support
{% endhint %}

Enumerations:

| Parameter      | Allowed values                                          |
| -------------- | ------------------------------------------------------- |
| callbackEvents | [Callback Events](/extra/references.md#callback-events) |

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

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

```
POST https://direct.revicom.ltd/api/v1/message
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json
[
  {
    "channelType": "VK",
    "senderName": "SENDER",
    "destination": "14085553911",
    "content": "message text https://domain.com",
    "localSendTime": "2022-01-01 18:00:00",
    "localCompletionTime": "2022-01-02 18:00:00",
    "useLocalTime": true,
    "shortUrl": true,
    "ttl": 43200,
    "hours": [
      12,
      13,
      14,
      15,
      16,
      17,
      18,
      19
    ],
    "days": [
      1,
      2,
      3,
      4,
      5,
      6,
      7
    ],
    "callbackUrl": "https://company.com/callback",
    "callbackEvents": [
      "delivered",
      "read"
    ],
    "tags": [
      "tag1",
      "tag2"
    ]
  }
]
```

{% endtab %}

{% tab title="cURL" %}

```
curl -X POST 'https://direct.revicom.ltd/api/v1/message' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' \
-d '[{"channelType":"VK","senderName":"SENDER","destination":"79818268484","content":"message text https://domain.com","localSendTime":"2022-01-01 18:00:00","localCompletionTime":"2022-01-02 18:00:00","useLocalTime":true,"shortUrl":true,"ttl":43200,"hours":[12,13,14,15,16,17,18,19],"days":[1,2,3,4,5,6,7],"callbackUrl":"https://company.com/callback","callbackEvents":["delivered","read"],"tags":["tag1","tag2"]}]'
```

{% endtab %}
{% endtabs %}
