Notifications to specified users

To send notifications to users by their IDs, use the following OK API methods:

For details on working with OK API, see Server-side API calls.

Send a notification to one user

To send a single notification to a specific user by their ID on OK, use the notifications.sendSimple method.

Limitations

  • Only one notification can be sent per request.
  • No more than 5 notifications per day can be sent to a single user.
  • Only users who have launched the app within the last 14 days will receive notifications.
  • A user can see only one notification from the app at a time, so a new notification will replace the previous one if it hasn’t been dismissed yet.

Request parameters

When calling OK API, you also need to pass the common request parameters.

Field
Type
Description
text
string
Required. Notification text. Max 100 characters. No more than 5 special characters or emojis are allowed.
uid
integer
Required. ID of the user who will receive the notification.
custom_button_key
string
Action button key in the notification. Default: button_launch (Start playing).

Example

Send the notification “Your friend needs help” to the user with ID 123456789. The notification will show the “More details” button.

If the request is successful, the response will be true.

CURL

Bash
curl 'https://api.ok.ru/fb.do' \ -X POST \ -F 'application_key=<public_key>' \ -F 'method=notifications.sendSimple' \ -F 'uid=123456789' \ -F 'text=Your friend needs help' \ -F 'custom_button_key=button_more' \ -F 'sig=<request_signature>'

JavaScript (Node.js)

JavaScript
const params = { uid: '123456789', text: 'Your friend needs help', custom_button_key: 'button_more' }; callAPI('notifications.sendSimple', params) .then(data => console.log(data));

An example of the callAPI function that generates the request signature is described in Working with OK API.

Send a batch of notifications to different users

To send a batch of notifications to users by their IDs on OK in a single request, use the notifications.sendList method.

Limitations 

  • The method accepts an array of up to 100 notifications.
  • No more than 5 notifications per day can be sent to a single user.
  • Only users who have launched the app within the last 14 days will receive notifications.
  • A user can see only one notification from the app at a time, so a new notification will replace the previous one if it hasn’t been dismissed yet.

Request parameters 

When calling OK API, you also need to pass the common request parameters.

Field
Type
Description
notifications
NotificationList
Required. Notification array. Max 100 items.

NotificationList contains objects with the following fields:

Field
Type
Description
message
string
Required. Notification text. Max 128 characters.
user_id
integer
Required. ID of the user who will receive the notification.
fragment
string
Additional parameter that will be added to the notification hash and passed to the app.
button
string
Action button key in the notification. Default: button_launch (Start playing).

Response parameters

Field
Type
Description
user_id
string
ID of the user who received the notification.
notification_result
string
Notification delivery status: OK

Example 

Send two notifications to different users:

  • Send the message “Claim your gift” with the “Accept” button to user 123456789; pass an arbitrary parameter gift to the app.
  • Send the message “A bonus is waiting for you” with the “Start playing” button to user 555666777.

If the request is successful, the response will be returned in the following format:

JSON
{ "notifications": [ { "user_id": 123456789, "notification_result": "OK" }, { "user_id": 555666777, "notification_result": "OK" } ] }

CURL

Bash
curl 'https://api.ok.ru/fb.do' \ -X POST \ -F 'application_key=<public_key>' \ -F 'method=notifications.sendList' \ -F 'notifications={"notifications":[{"user_id":123456789,"message":"Claim your gift","fragment":"gift","button":"button_accept"},{"user_id":555666777,"message":"A bonus is waiting for you","button":"button_launch"}]}' \ -F 'sig=<request_signature>'

JavaScript (Node.js)

JavaScript
const params = { notifications: JSON.stringify({ notifications: [ { user_id: 123456789, message: "Claim your gift", fragment: "gift", button: "button_accept" }, { user_id: 555666777, message: "A bonus is waiting for you", button: "button_launch" } ] }) }; callAPI('notifications.sendList', params)

An example of the callAPI function that generates the request signature is described in Working with OK API.

Action button in a notification

You can choose which text will be displayed on the action button in the notification:

  • button_join — Join.
  • button_accept — Accept.
  • button_attach_badge — Attach.
  • button_attend — I’ll go.
  • button_close — Close.
  • button_confirmFriend — Confirm.
  • button_decline — Decline.
  • button_enable — Enable.
  • button_hide — Hide.
  • button_install — Install.
  • button_launch — Start playing.
  • button_launch_app — Launch.
  • button_more — More details.
  • button_open — View.
  • button_open_all — View all.
  • button_pay — Pay.
  • button_realProlong — Extend.
  • button_rejectRequest — Reject.
  • button_sendPresent — Gift.
  • button_show — Show.
  • button_subscribe — Subscribe.
  • button_unsubscribe_cancel — Cancel.
  • button_use_coupon — Use coupon.
  • button_view — See what’s inside.

Related materials