Push Messages

Location /api/apps/{appID}/users/me/push/messages
This resource represents the push messages sent to the current user.

Request Headers (Applies to all methods)

Authorization
header
Required: Yes

POST

/api/apps/{appID}/users/me/push/messages

Description

Send a push message to the current user. A 400 status error with code INVALID_INPUT_DATA will be returned in the following scenarios:

  • "gcm" or "apns" fields are not provided in the request.
  • "gcm.enabled" or "apns.enabled" fields are not provided in the request.
  • "gcm.dryRun" and "apns.enabled" are both set to true.
  • "data" contains nested JSONs or arrays.
  • "gcm.data" contains values different from String.
  • "apns.enabled" is true and "apns.data" contains nested JSONs or arrays.
  • "gcm.enabled" is set to true and "data" or "gcm.data" contains a key that starts with the prefix "google." or is one of these values:
    • from
    • registration_ids
    • collapse_key
    • data
    • delay_while_idle
    • time_to_live
    • restricted_package_name
    • dry_run
  • "fcm.enabled" is set to true and "data" or "fcm.data" contains a key that starts with the prefixes "google." or "gcm." or is one of these values:
    • from
    • message_type
    • collapse_key
    • priority
    • ttl
    • restricted_package_name
    • notification
    • fcm_options
    • direct_boot_ok
  • "gcm.enabled" is true and the payload for Android-GCM exceeds 4096 bytes.
  • "apns.enabled" is true and the payload for iOS-APNS exceeds 2048 bytes.

If both GCM and FCM specific fields are enabled, the FCM push notification will be prioritized.


FCM-specific fields:

Field Type Description
enabled Boolean. Required. If true, it will send the message to the FCM installations of the subscribed users.
data JSON Object with only one-level of nesting, and only strings in values. Dictionary with the data that will be sent only to Android-FCM devices.
notification JSON Object with the following format:
Name Type Description
title String Notification title
body String Notification body
image String The url of the image
Notification template.
android JSON Object with the following format:
Name Type Description
collapseKey String Identifier for group of messages
priority Enum
  • NORMAL
  • HIGH
Message priority
ttl String How long the message is kept in FCM storage when device is offline
restrictedPackageName String Package name of the app
directBootOk Boolean If true, the message will be delivered to the app while the device is in direct boot mode
notification
Name Type
title String
body String
icon String
color String
sound String
tag String
clickAction String
bodyLocArgs String[]
titleLocKey String
titleLocArgs String[]
channelID String
ticker String
sticky Boolean
eventTime String (Timestamp format)
localOnly Boolean
notificationPriority Enum:
  • PRIORITY_UNSPECIFIED
  • PRIORITY_MIN
  • PRIORITY_LOW
  • PRIORITY_DEFAULT
  • PRIORITY_HIGH
  • PRIORITY_MAX
defaultSound Boolean
defaultVibrateTimings Boolean
defaultLightSettings Boolean
vibrateTimings String[] (Duration format)
visibility Enum:
  • VISIBILITY_UNSPECIFIED
  • PRIVATE
  • PUBLIC
  • SECRET
notificationCount Integer
lightSettings JsonObject
{
    "color": {
        "red": number,
        "green": number,
        "blue": number,
        "alpha": number
    },
    "lightOnDuration": String (Duration format),
    "lightOffDuration": String (Duration format)
}
image String
Notification for Android devices
Android specific options for messages.

GCM-specific fields:

Field Type Description
enabled Boolean. Required. If true, it will send the message to the GCM installations of the subscribed users.
data JSON Object with only one-level of nesting, and only strings in values. Dictionary with the data that will be sent only to Android-GCM devices.
notification Notification payload. We supports title, body, icon, sound, tag, color and clickAction fields in notification. Other fields are not supported yet.
collapseKey String. Not required. If provided, it will be used as the GCM notification collapse_key
delayWhileIdle Boolean. Not required. If provided, it will be used as the GCM notification delay_while_idle
timeToLive Integer. Not required. If provided, it will be used as the GCM notification time_to_live
restrictedPackageName String. Not required. If provided, it will be used as the GCM restricted_package_name
dryRun Boolean. Not required. If true, the only system that can be enabled is “GCM” - no other system will be accepted. If provided, it will be used as the GCM dry_run

iOS-APNS specific fields:

Field Type Description
enabled Boolean. Required. If true, it will send the message to the APNS installations of the subscribed users.
data JSON Object with only one-level of nesting, and only strings, integers, booleans or doubles in the values. Dictionary with the data that will be sent only to iOS-APNS devices.
alert JSON Object with the format:
Field Type
title String. Not required.
subtitle String. Not required.
body String. Not required.
actionLocKey String. Not required.
locKey String. Not required.
locArgs JSON Array of values. Not required.
launchImage String. Not required.
All the information related to the alert that will be shown when the notification is received with the app turned off. See details in APNS documentation.
sound String. Not required. If provided, it will be used as the “sound” to be sent with the notification. See details in APNS documentation.
badge Number. Not required. If provided, it will be used as the “badge” to be sent with the notification. See details in APNS documentation.
contentAvailable Boolean. Not required. If provided and has "true" value, it will be set "1" to the field "content-available" in the notification, otherwise that field will not be sent. See details in APNS documentation.
category String. Not required. If provided, it will be used as the “category” to be sent with the notification. See details in APNS documentation.
mutableContent Boolean. Not required. If provided and has "true" value, the value "1" will be set to the field "mutable-content" in the notification; otherwise the field will not be sent. See details in APNS documentation.

JPUSH specific fields:

Field Type Description
enabled Boolean. Required. If true, it will send the message to the JPUSH installations of the subscribed users.
data JSON Object with only one-level of nesting, and only strings in values. Dictionary with the data that will be sent only to JPUSH devices.

MQTT specific fields:

Field Type Description
enabled Boolean. Required. If true, it will send the message to the MQTT installations of the subscribed users.
data JSON Object with only one-level of nesting, and only strings in values. Dictionary with the data that will be sent only to MQTT devices.
dryRun Boolean. Not required, Used for testing. If provided with "true" value, the message will not be sent to the device. Default is "false".
retain Boolean. Not required. Retain message. (currently always false)
qos Integer. Not required. Quality of service for the message (default will be 0 - fire and forget)

Security

Can be performed only by administrator

Content-Type application/vnd.kii.SendPushMessageRequest+json

All the data to a send message. The format of the request and responses is the same as in send a push message to a topic and applies the same validation rules, but in this case the fields sendAppID, sendObjectScope and sendTopicID do not apply, since there is not a topic involved.

Headers
Name Required? type Description
Authorization Yes string Authorization header. OAuth2 Bearer token
Params
Name Required? Type Description
data JSONObject Dictionary with the data that will be sent to all the push systems enabled in this request.
sendToDevelopment boolean If true this message will be sent to the devices that have the property "development" to "true" in their installations. Default is true.
sendToProduction boolean If true this message will be sent to the devices that have the property "development" to "false" or null in their installations. Default is true.
pushMessageType string Value that will optionally indicate what is the type of the message. Event-generated push messages contain it.
sendSender boolean If true, send the “sender” field (userID of the user that triggered the notification). Default is true.
sendWhen boolean If true, send the “when” field (when the push message was sent). Default is false.
sendOrigin boolean If true, send the “origin” field (indicates if the message is the result of an event or sent explicitly by someone. Default is false.
sendAppID boolean If true, the appID field will also be sent. Default is false.
sendObjectScope boolean If true, send the “objectScope”-related fields that contain the topic that is the source of this notification. Default is true.
sendTopicID boolean If true, send the “topicID” field that contains the topicID that is the source of this notification. Default is true.
sendSourceURI boolean If true, send the "sourceURI" field containing the URI that identifies the source of this notification. Default is true.
sendSenderURI boolean If true, send the "senderURI" field containing the URI that indentifies the sender of this notification. Default is true.
fcm FCMType FCM-specific fields.
enabled boolean If true, it will send the message to the FCM installations of the subscribed users.
data JSONObject Dictionary with the data that will be sent only to Android-FCM devices.
token|topic|condition string Notification target. Just one at the same time.
notification JSONObject Notification template.
android JSONObject Android specific options for messages.
directBootOk boolean If true, the message will be delivered to the app while the device is in direct boot mode
gcm GCMType GCM-specific fields.
enabled boolean if true, it will send the message to the GCM installations of the subscribed users.
data JSONObject Dictionary with the data that will be sent only to Android-GCM devices.
notification JSONObject Notification payload that will be sent only to Android-GCM devices.
collapseKey string If provided, it will be used as the GCM notification collapse_key
delayWhileIdle boolean If provided, it will be used as the GCM notification delay_while_idle
timeToLive int If provided, it will be used as the GCM notification time_to_live
restrictedPackageName string If provided, it will be used as the GCM restricted_package_name
dryRun boolean If provided, it will be used as the GCM dry_run
apns APNSType iOS-APNS specific fields.
enabled boolean if true, it will send the message to the APNS installations of the subscribed users.
data JSONObject Dictionary with the data that will be sent only to iOS-APNS devices.
alert JSONObjectAPNSType All the information related to the alert that will be shown when the notification is received with the app turned off. See details in APNS documentation.
badge float If provided, it will be used as the “badge” to be sent with the notification. See details in APNS documentation.
sound string If provided, it will be used as the “sound” to be sent with the notification. See details in APNS documentation.
contentAvailable boolean If provided and has "true" value, it will be set "1" to the field "content-available" in the notification, otherwise that field will not be sent. See details in APNS documentation.
category string If provided, it will be used as the “category” to be sent with the notification. See details in APNS documentation.
mutableContent boolean If provided and has "true" value, it will be set "1" to the field "mutable-content" in the notification, otherwise that field will not be sent. See details in APNS documentation.
jpush JPUSHType JPUSH specific fields.
enabled boolean if true, it will send the message to the JPUSH installations of the subscribed users.
data JSONObject Dictionary with the data that will be sent only to JPUSH devices.
mqtt MQTTType MQTT specific fields.
enabled boolean if true, it will send the message to the MQTT installations of the subscribed users.
data JSONObject Dictionary with the data that will be sent only to MQTT devices.
dryRun boolean Used for testing, if provided with "true" value the message will not be sent to the device. Default is "false".
retain boolean Retain message. (currently always false)
qos int Quality of service for the message (default will be 0 - fire and forget)
Sample Request
{
  "data": "[JSONObject]",
  "sendToDevelopment": "[boolean]",
  "sendToProduction": "[boolean]",
  "pushMessageType": "[string]",
  "sendSender": "[boolean]",
  "sendWhen": "[boolean]",
  "sendOrigin": "[boolean]",
  "sendAppID": "[boolean]",
  "sendObjectScope": "[boolean]",
  "sendTopicID": "[boolean]",
  "sendSourceURI": "[boolean]",
  "sendSenderURI": "[boolean]",
  "fcm": "[FCMType]",
  "gcm": "[GCMType]",
  "apns": "[APNSType]",
  "jpush": "[JPUSHType]",
  "mqtt": "[MQTTType]"
}
Responses
200

Content-Type application/vnd.kii.SendPushMessageResponse+json

The message will be sent in an asynchronous fashion.
Contents
Name Type Description
pushMessageID string The ID of the sent message
404

Content-Type application/vnd.kii.UserNotFoundException+json

The user was not found.
Contents
Name Type Description
errorCode string Error code "USER_NOT_FOUND".
message string The error message.
field string The field used for searching the user. This can be the userID or address field.
value string The field value used for searching the user.
appID string The ID of the application.
401

Content-Type application/vnd.kii.UnauthorizedAccessException+json

Not authorized to send a message to the user.
Contents
Name Type Description
errorCode string Error code "UNAUTHORIZED".
message string The error message.
authenticatedAppID string The authenticated appID.
authenticatedPrincipalID string The authenticated principal ID (userID or thingID).