Subscribing to a Topic

Subscription to a topic is necessary to receive Push to User notifications. Once a user subscribes to a topic, all push messages sent to this topic will be delivered to the user.

The following curl execution subscribes to an application-scope topic named SendingAlert.

curl -v -X PUT \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  "https://api.kii.com/api/apps/{APP_ID}/topics/SendingAlert/push/subscriptions/users/{TARGET_USER_ID}" \
  -d ""

The next sample curl execution subscribes to a group-scope topic named GroupTopic.

curl -v -X PUT \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  "https://api.kii.com/api/apps/{APP_ID}/groups/{GROUP_ID}/topics/GroupTopic/push/subscriptions/users/{TARGET_USER_ID}" \
  -d ""

The last sample curl execution subscribes to a user-scope topic named MyTODO.

curl -v -X PUT \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  "https://api.kii.com/api/apps/{APP_ID}/users/{USER_ID}/topics/MyTODO/push/subscriptions/users/{TARGET_USER_ID}" \
  -d ""

For all cases, make sure to replace {APP_ID} with your application's AppID and TARGET_USER_ID with the target user's ID. Also make sure to replace {ACCESS_TOKEN} with the target user's token or the app admin token.

If you are subscribing the current user (i.e. the user to whom the ACCESS_TOKEN belongs), you can skip the TARGET_USER_ID like in the following example (note that you need to use POST, not PUT, in this case):

curl -v -X POST \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  "https://api.kii.com/api/apps/{APP_ID}/topics/SendingAlert/push/subscriptions/users" \
  -d ""

Kii Cloud will respond as follows:

  • Returns a 204 response if the subscription is successful.
  • Returns a 404 response with the error code TOPIC_NOT_FOUND if the specified topic does not exist.
  • Returns a 409 response with the error code PUSH_SUBSCRIPTION_ALREADY_EXISTS if the user is already subscribed.