Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Problem with server code push

Have run into a problem with server code push notifications:

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?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

Problem with server code push

figured it out, I defined the array containing the channel as a valriable 'ch' as follows:

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 body = JSON.parse(request.body());
var message = body.message;
var channel = body.channel;
console.log("body",body);
console.log("message = ",message);
console.log("channel = ",channel);
var ch = [channel];
Apperyio.PN.send(pushApiKey, {
payload: {
"message": message
},
filter: {
"channels": {
"$in": ch
}
}
});
Apperyio.response.success({"push":"success"}, "application/json");
/code

However, i would still like to know if I can check the status and return some diagnostic info if it fails

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Problem with server code push

Terry,

The latter is (as an example of not returning success...)...

response.error('Error - retreiving Control Record: ' + e.message, 500);

The 500 is the code I'm returning - and - if you received an error that you 'caught' in a try{} catch(e) {
... You might put the code below.... like such
response.error('Error - retreiving Control Record: ' + e.message, 500);

}

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Problem with server code push

I don't know about your other issue....

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Problem with server code push

Hello,

It is impossible to check the response from APNS or Google Cloud Messages, because they accept all requests and have responses only after sending notifications to clients

Return to “Issues”