Leveraging Push Notifications

Kii Cloud supports three types of push notifications. Of these, you can leverage Push to App Notification and Push to User Notification with things.

Types of push notifications

Push to App notification

You can leverage Push to App notifications just the same way as you do in the application, group or user scope. See Receiving a Push to App Notification section to see how you can operate various tasks related to the Push to App notification feature.

Remember that you need to specify the appropriate thing scope bucket. For example, you will access the following resource URL when you are to subscribe a thing bucket.

  • https://api.kii.com/api/apps/{APP_ID}/things/{Thing_ID}/buckets/{BUCKET_ID}/
    filters/all/push/subscriptions/things/{THING_ID}

Push to User notification

You can leverage Push to User notifications just the same way as you do in the application, group or user scope. See Push to User Notification section to see how you can operate various tasks related to the Push to User notification feature.

Remember that you need to specify the appropriate thing scope topic. For example, you will access the following resource URL when you are to subscribe a thing topic.

  • https://api.kii.com/api/apps/{APP_ID}/things/{Thing_ID}/topics/{TOPIC_NAME}/
    push/subscriptions/things/{THING_ID}

Detailed information in a push notification

When you get a push message from Kii Cloud with the MQTT's PUBLISH command, the detail information of the push notification will be set in its payload (in JSON format with the maximum size of 4096 bytes).

For the precise explanation of the payload see [KiiUser currentUser].pushSubscription in the Android SDK Javadoc. The keys stored in the first level of the JSON correspond to the fields explained in the Javadoc.

Ensure to check the MQTT topic name on receiving the PUBLISH command from the server because the PUBLISH command is used for various purposes. The MQTT topic name that you receive as part of push notification is the one you specified when you executed the SUBSCRIBE command, that is, "mqttTopic" in Retrieve an MQTT Endpoint. Also, ignore PUBLISH commands with unknown MQTT topic names for future enhancement.

Here is a couple of examples (Note that real messages will not have any carriage return)

Push to App notification message

This example shows a message sent when a new object is created in a thing-scope bucket.

{
  "appID": "11112222",
  "bucketID": "myBucket",
  "bucketType": "rw",
  "modifiedAt": 1424942605290,
  "objectID": "1da424a0-bd99-11e4-838f-22000a78437b",
  "objectScopeAppID": "11112222",
  "objectScopeThingID": "th.dfa848a00022-faea-4e11-97db-0b63263f",
  "objectScopeType": "APP_AND_THING",
  "origin": "EVENT",
  "sender": "th.dfa848a00022-faea-4e11-97db-0b63263f",
  "type": "DATA_OBJECT_CREATED",
  "when": 1424942605309
}

Push to User notification message

This example shows a message sent when a new message that has two values (Done and Item) is sent to a thing-scope topic named "MyTODO".

{
  "Done": "0",
  "Item": "Do something",
  "objectScopeAppID": "11112222",
  "objectScopeThingID": "th.dfa848a00022-faea-4e11-97db-0b63263f",
  "objectScopeType": "APP_AND_THING",
  "sender": "th.dfa848a00022-faea-4e11-97db-0b63263f",
  "topic": "MyTODO",
  "when": 1424943553656
}