Push Notification API: Working with RuStore, FCM, and HMS
The API is designed to provide the ability to send push notifications by topic through multiple push providers simultaneously.
To send a push notification, use the POST method at https://vkpns-universal.rustore.ru/v1/send/topic.
To send a push notification to a topic, you must specify the Project ID and Authorization Token for each provider through which you plan to send push notifications.
- RuStore
- FCM
- HMS
Use project_id (Project ID) and ss_token (service token). You can obtain these values in the RuStore Console system. To do this, go to the Push Notifications section on the app page and select Projects. Sending Push Notifications.
These values can be obtained in the RuStore Console system. Examples of obtaining the token are described in the FCM documentation.
- https://firebase.google.com/docs/cloud-messaging/migrate-v1#use-credentials-to-mint-access-tokens;
- https://firebase.google.com/docs/cloud-messaging/auth-server.
RuStore does not store the Project ID and Authorization Token. Validate the token yourself.
These values can be obtained in the RuStore Console system. An example of obtaining the Authorization Token is available in the documentation. The Project ID can be obtained in the developer console; do not confuse it with the App ID, which is described in the documentation.
RuStore does not store the Project ID and Authorization Token. Validate the token yourself.
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
providers | object (providers) | yes | Providers for sending push notifications. |
topic | string | yes | Topic name. |
message | object (message) | yes | Push notification structure. |
providers
| Parameter | Type | Required | Description |
|---|---|---|---|
rustore | object (provider) | no | RuStore provider. |
fcm | object (provider) | no | Firebase provider. |
hms | object (provider) | no | Huawei provider. |
providers.provider
| Parameter | Type | Required | Description |
|---|---|---|---|
project_id | string | yes | Project ID. |
auth_token | string | yes | Authorization token. |
message
| Parameter | Type | Required | Description |
|---|---|---|---|
data | map | no | An object containing "key": value pairs. |
notification | object (message.notification) | yes | Basic notification template for use on all platforms. |
android | object (message.android) | HMS only | Android-specific parameters for messages. |
message.notification
| Parameter | Type | Required | Description |
|---|---|---|---|
title | string | yes | Notification title. |
body | string | yes | Notification body text. |
image | string | no | Contains a URL to an image to be displayed in the notification. |
message.android
| Parameter | Type | Required | Description |
|---|---|---|---|
ttl | string (duration format) | no | How long (in seconds) the message should be stored. Example: 3.5s. |
notification | object (message.android.notification) | HMS only | Notification for sending to Android devices. |
message.android.notification
| Parameter | Type | Required | Description |
|---|---|---|---|
title | string | yes | Notification title. |
body | string | yes | Notification body text. |
icon | string | no | Notification icon. |
color | string | no | Notification icon color in #rrggbb format. |
image | string | no | Contains a URL to an image to be displayed in the notification. |
channel_id | string | no | Notification channel ID. |
click_action | string | no | Action associated with the user clicking the notification. In HMS, the default type is 1 (intent). |
Only the fields listed above are supported in the message structure.
Successful Response Body
| Parameter | Type | Description |
|---|---|---|
status | string | On successful response, returns a message with status OK. |
Error Body
| Parameter | Type | Description |
|---|---|---|
code | number | Numeric error code (404, 400, 403, 401, ...). |
status | string | General error description. |
errors | array (string) | Provider-specific errors or validation errors. |
HTTP status corresponds to the code field.
Errors are divided into three types
- Message validation errors.
- Provider sending errors.
- Service errors.
Possible errors when sending a message
VALIDATION_ERROR— incorrectly specified request parameters when sending a message.PROVIDER_ERROR— error sending to the push provider.INTERNAL_ERROR— internal service error.
Possible validation errors when sending a message
providers.%provider_name%— error in the provider.message.%field%— error in the message.
Possible provider errors when sending a message, in the format %provider_name%: %error%
internal— internal provider error.validation error— validation error on the provider side.invalid auth token— auth token error.too many requests— too many requests.
Validation Algorithm
A provider must have tokens.
providers
At least one provider must be specified; without providers, the request is invalid.
message
- If there is a non-empty
payloadmessage.data(i.e., at least one key-value pair inside), the message is valid. Themessage.notificationandmessage.androidsections may be absent. - If the
message.datafield is absent,notificationmust be present. In this case, eithermessage.notificationormessage.android.notificationmust be present. At least one of these fields must be present, but both may be present (if both are present, some fields are overwritten).
Limitations
- If the notification does not have a
ttlfield or it equals0, the default value of 4 weeks is used. If themessage.androidsection is absent, it is added with thettlfield. - Maximum message size is 4096 bytes.