Page 1 of 1

create a targeted push notification in server code using channels

Posted: Thu Apr 13, 2017 12:52 pm
by Terry Gilliver

I can't locate any info for creating targeted push notifications using channels. I want to do this in server code, so that I can call it as a service from an external website.


create a targeted push notification in server code using channels

Posted: Thu Apr 13, 2017 1:03 pm
by Terry Gilliver

OK, Sorted, found it in the code snippets


create a targeted push notification in server code using channels

Posted: Thu Apr 13, 2017 1:15 pm
by Serhii Kulibaba

Hello Terry,

Glad to hear things are sorted out now!


create a targeted push notification in server code using channels

Posted: Thu Apr 13, 2017 1:43 pm
by Terry Gilliver

Just run into an issue: Here is the code:

code// Push Notifications API key from:
// Apps > [App] > Push Notifications > Settings
// 'badge' is iOS only setting

var pushApiKey = "0813456a-4b56-4386-97a1-b3daacf5c3ee&quot
var message = request.get("message");
var channel = request.get("channel");
console.log("message = ",message);
console.log("channel = ",channel);
Apperyio.PN.send(pushApiKey, {
payload: {
"message": message
},
filter: {
"channels": {
"$in": [channel]
}
}
});/code

If I test this, the message is not sent, but there are no errors. The problem is somewhere in the syntax for the channels filter, if I remove the filter, then the message is sent. The Channel is set to 2 in the database for all devices. See the screenshot below:
Image

also i have found how to send a success response using Apperyio.reponse.success, but can you check the response status, and is there an Apperyio.reponse.error function?