Push with API¶
Message publishing API supports the following scenarios:
Scenarios |
Description |
---|---|
Push notification from a Push Template |
This approach is the simplest and yet provides the most flexibility when it comes to identifying a dynamic audience of who will be receiving the notification, creating custom, personalized content for each recipient and configuring numerous visual and audible effects. To send out push notifications for a Push Template using the API, make sure to start with defining a Push Template first. For more information see the About Push Templates section of the guide. API Example. |
Basic push notification |
It is the simplest form of a push notification. It is sent to a channel and all devices registered with the channel will be receiving the notification. The notification message must contain headers which control the appearance of the notification on the devices. API Example. |
Push notification delivered to devices grouped by the OS |
With this type delivery, a notification is sent to all devices of a specific operating system (or a combination of). This includes delivery to Android, iOS or both. API Example. |
Push notification delivered to specific devices |
This delivery type allows push notification delivery to individual devices. API Example |
Delayed publishing |
For all scenarios described above a push notification request can be configured to be executed at a later time. API Example. |
Publishes push notification to a channel. Headers must be added to the publishOptions
argument. The deliveryOptions
argument can be used to:
- Singlecast publishing - Set a list of devices which should be receiving the notification.
- Broadcast publishing - Identify operating systems of the registered devices which should be receiving the notification.
- Publish the message at a later time (delayed publishing).
- Specify that the message should be republished multiple times (repeated publishing).
Backendless.Messaging.publish( channelName,
message,
publishOptions,
deliveryOptions )
.then( function( response ) {
})
.catch( function( error ) {
});
where:
Argument | Description |
---|---|
channelName |
Name of the channel to publish the message to. If the channel does not exist, Backendless automatically creates it. |
message |
Object/data to publish. Can be a primitive value, an array or a complex type. |
publishOptions |
Required argument. An instance of the Backendless.PublishOptions class. Contains publisher ID and/or message headers. |
deliveryOptions |
Optional argument. An instance of the Backendless.DeliveryOptions class. May specify timestamp (in milliseconds) for publishing at the specified time in the future or interval for repeated publishing. |
Return value¶
An untyped JavaScript object containing message ID and the status of the publishing operation:
{
status : "published" | "scheduled" | "failed",
messageId: messageIdValue
}
Errors¶
The following errors may occur during the message publishing API call. See the Error Handling section for details on how to retrieve the error code when the server returns an error:
Error Code |
Description |
---|---|
5003 |
Invalid repeatExpiresAt date in delivery options. |
5007 |
User does not have the permission to publish messages |
5030 |
Invalid publishAt date in the delivery options. |