Skip to content

Push with API

Message publishing API supports the following scenarios:

  • 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.

Method

POST

URL

https://api.backendless.com/<application-id>/<REST-api-key>/messaging/<channel-name>

where:

Argument                Description
<application-id> the ID of your application generated upon its creation. You can get the value in the Manage > App Settings section of the Backendless Console.
<REST-api-key> REST API key of your application. You can get the value from the Manage > App Settings section of the Backendless Console.
<channel-name> name of the channel to publish the message to.

Request Headers

Content-Type: application/json  
user-token: optional value obtained as a result of the login operation.

where:

Argument                Description
Content-Type Must be set to application/json. This header is mandatory.
user-token Optional header. Contains a value returned by Backendless in a preceding user Login API call. If user-token is set in the request, the operation will be executed with the security policy associated with the currently logged in user. This means all permissions associated with the user and the roles assigned to the user will be enforced by Backendless.

Request Body:

Optional parameters are shown in [square brackets]:

{  
  "message" : value,  
  ["publisherId" : value,]  
"headers": {"key1":"value1","key2":"value2"}  
  ["publishPolicy":"PUSH"]  
  ["pushBroadcast" : IOS | ANDROID | ALL,] // value is a mask  
  ["pushSinglecast": ["deviceId1", "deviceId2",] // value is an array  
  ["publishAt":timestamp,] // value in milliseconds  
  ["repeatEvery":frequency-in-seconds,]  
  ["repeatExpiresAt":expiration-timestamp] // value in milliseconds  
}

where:

Argument                Description
headers must contain headers controlling the content and appearance of the push notification on the devices.
publishPolicy if set to PUSH, message is published only as push notification, otherwise if the value is BOTH, the message is published as both push notification and a pub/sub message
pushBroadcast Must be a value calculated as an OR mask from the following constants: IOS = 1, ANDROID = 2, WP = 4, ALL = 7 (IOS
pushSinglecast contains a JSON array of device  IDs which will be receiving the push notification.
publishAt is a timestamp when the push notification should be sent.
releatEvery is a number of seconds defining the frequency of sending the notification.
repeatExpiresAt is a timestamp when the repeat publishing operation of the push notification must stop.

Response Body

{  
  "status" : "scheduled" | "failed",  
  "messageId": messageId  
}

In order to obtain message publishing status, use the Get Message Status API with the messageId value returned by the message publishing request.

Errors

When the server-side reports an error, it returns a JSON object in the following format:

{  
  "message":error-message,  
  "code":error-code  
}

The following errors may occur during the message publishing API call:

Error Code
Description
5003
Invalid repeatExpiresAt date
5007
User does not have the permission to publish messages
5030
Invalid publishAt date