Sending push notification using template to selected devices via API


I have defined a Push Template with some smart text in the message body and a Button Options. I want to deliver notifications just to a selected devices using this template, and I want to put a custom header on it to be retrieved later in the activity associated to the button (the value of the header will be an objectId of a register in a custom table).

How can I deliver notifications using this template via API?

I have seen there are to methods signature for Backendless.Messaging.pushWithTemplate. One of them receives a Map as second argument.

Where do I put the query for the selected devices?
Where do I put the value of the custom header?

Best regards

Hello @Nono_Carballo,

second argument is for template values (substitutions for smart text).

So you can define a smart text in your custom header (e.g. headerObjectId) and then send template with second argument as {"headerObjectId": "your-object-id-value-here"}


Thanks, I will try this

What about the query to select the devices that will receive the notification? How do I send the query in the API call?

Best regards

Hello @Nono_Carballo

In order to select the devices to which notifications will be sent, follow the instructions described in the documentation - Notification Audience (WHO)
It is not possible to establish recipients in other ways, including in the request.

I had same issue…

Hello @Graham_Reddie, Hello @Nono_Carballo

For more info about Push with API.

Thank you - however for the moment it’s not possible to use a template and via the API to set the Segment of the template which is what I think @Nono_Carballo wanted to do too.

1 Like

Yes, you are right, at the moment it is impossible to use a template and install a template segment through the API, only through the console, as I wrote above.

1 Like

Is there any alternative? Is there a way to send push notifications with same setup as push templates via other API calls?

Nor the channel can be sent in the second parameter?

I’m thinking in registering a device on more than one channel (column channelName in Users table seems to accept multiple values), if I could then send a push notification using the template and indicate the target channel, that will be fine.

Push templates contain settings to whom to send notifications. When calling via API, you can specify only the name of the template and templateValues, which contains the values ​​for replacing the sartText. In this case, you cannot override the recipient list in any way.

In order to send notifications through the API and specify a list of recipients, you can use one of the following calls:

  1. Push notification delivered to devices grouped by the OS
  2. Push notification delivered to specific devices
  3. For a specific channel

In addition, when sending a notification, you can specify PublishOptions, which duplicates the settings that you see in push templates.

Hey @Nono_Carballo from what I understand you’d need to create your own Templates from scratch and then apply those parameter, channel and segmentation but dev will confirm no doubt.

Could you please elaborate more on this?

Can I insert smart text in the segment where clause for being replaced later by values sent in templateValues?

Yes @Graham_Reddie, that seems to be the way.

SmartText can be added where there is add smart textadd smart text :



For segment where smart text cannot be added

Thanks @Vladimir_Yalovy,

Could you elaborate more on how can I duplicate push templates settings with PublishOptions, as you mentioned before? Maybe that is the way.

When sending push notifications via API, except when sent using templates, for example Basic Push, you specify PublishOptions.

new Backendless.PublishOptions ({
        headers: {
            "android-ticker-text": "Your just got a push notification",
            "android-content-title": "This is a notification title",
            "android-content-text": "Push notifications are cool"

android-ticker-text - is android ticker text
android-content-title - is android content title
android-content-text - android content text

Sorry, but I don’t see how can I duplicate push templates settings with PublishOptions. The code you show just set content and ticket-text.

How using PublishOption can I:

  1. Set the activity to call when selected the notification in notification drawer
  2. Include buttons
  3. Send custom values

Best regards?

Hello @Nono_Carballo

Sorry for delay.

Perhaps I was mistaken when I said about duplicating template settings with PublishOptions, only a few settings are repeated there. Possible values for PublishOptions can be found here - Push Notification Headers

For now, I can offer you the following work-round: create several templates with different Segment and do Send Notification from a Push Template with the segment you need.

I will also consult with my colleagues, perhaps there is some other option. I will let you know about the result in this topic.

Thanks @Vladimir_Yalovy,

That will be a solution for me only if I could create Push Templates via API. I’m thinking on creating Push Templates via API (will all it’s settings) and specify a different channel on each one, then subscribe users to those channels, when I send push notification using the template just those users will receive the notification, that’s is what I want.

Waiting for the feedback from your colleagues.

Best regards

1 Like