Creating and managing notifications

This topic provides information on setting up and sending push notifications with the Apigee API backend as a service (BaaS). For high-level information, prerequisites, and tutorials, see Push notifications overview.

Creating notifications

When you create a notification, it is scheduled to be delivered to all applicable devices immediately unless the deliver property has been set. A notification may contain multiple messages (payloads), and each payload must be associated with a notifier in order to deliver that message to the associated app. This allows a single notification to be delivered to multiple apps across various services, and is useful if you want to send messages to multiple notifiers, such as development and production versions of both Apple and Google simultaneously.

Notification can be created via POST request to the BaaS API, or in the admin portal:

Under the notifier name, select one of the following to specify where your notification message should go:

All Devices to have the message sent to all devices.

Devices to have the message sent to a particular subset of devices. Enter a comma-separated list of device UUIDs in the box provided.

Users to have the message sent to a particular subset of users. Enter a comma-separated list of username values in the box provided.

Groups to have the message sent to a particular subset of user groups. Enter a comma-separated list of group paths in the box provided.

In the Notifier Message field, enter the message (payload) you want delivered.

If double-quotes are included in your message, you must escape them with a backslash.

Under Delivery, select one of the following to specify when the notification should be delivered:

Now to have the message delivered immediately.

Schedule for later to choose a date and time at which the message should be delivered.

Click Submit.

To create a notification to send multiple messages or target multiple platforms, see the cURL syntax for creating notifications.

To send notifications from iOS app code, you use the ApigeeAPSDestination and ApigeeAPSPayload classes.

With ApigeeAPSDestination, you specify where the notification should go (a particular user or device or user group, for example). With ApigeeAPSPayload, you specify the contents of the message, including any alert text, sound, or badge (items specified by Apple as allowable notification content types). You then use ApigeeDataClient to send the message via Apigee and Apple APNs.

The following code illustrates how to send a notification to a single user. Though this is the device on which the app itself is installed, you can imagine how you might send a notification to another device, such as one belonging to someone "following" this user. For more, see the iOS push sample application included with the Apigee iOS SDK.

Request body syntax

Setting a notification expiration

If a push service can't deliver a message to a device and needs to resend it (for example, if the device is turned off), you can set a notification to expire after a certain date/time.

To do this, adding the expire parameter with a UNIX timestamp to your request body. This specifies when the service should stop trying to send the notification.

Please note that if the expire property is not set and Apple APNS or Google GCM are not able to immediately deliver your push notification, delivery will not be retried. This means your notification will not be delivered.

As a best practice, you should always set an expire timestamp to ensure your notification is delivered in the event the delivery initially fails.

Notification endpoints

The /notifications endpoints let you create, schedule, cancel, and delete notifications. You can also use the following endpoints to accomplish the same actions for specific groups, users, devices, or any combination thereof.