Skip to content

General API

A Backendless application can publish messages to Backendless for subsequent distribution to subscribers. A message must be published to a channel. Backendless supports unlimited number of channels per application. Channels can be used as a filtering mechanism - subscribers see the messages published only to the channel they subscribe to.

There is only one API for all types of message publishing. It supports the following scenarios:

API Specification

Non-Blocking API

Backendless.Messaging.publish( channelName, 
                               message, 
                               publishOptions, 
                               deliveryOptions )
 .then( function( response ) {
  })
 .catch( function( error ) {
  });

Blocking API

var response = Backendless.Messaging.publishSync( channelName, 
                                                  message, 
                                                  publishOptions, 
                                                  deliveryOptions );

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 to publish. Can be a primitive value, an array or a complex type.
publishOptions optional argument. An instance of the Backendless.PublishOptions class. Contains publisher ID, and message headers. See the Publish with Headers section for examples.
deliveryOptions optional argument. An instance of the Backendless.DeliveryOptions class. May specify message delivery policy, timestamp (in milliseconds) for publishing at the specified time in the future, interval for repeated publishing. See the Delayed Publish and Repeated Publish sections for examples.

Return value

A JavaScript object containing message ID and the status of the publishing operation. In order to obtain message delivery status, use the Get Message Status API with the messageId value returned by this API.

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