I've studied the pushwoosh romote api,the basic process to send a notification is to post a piece of JSON data to http://cp.pushwoosh.com/json/1.3/createMessage and to be specific,the data will be packaged in the format like
{'application' : PW_APPLICATION,
'auth' : PW_AUTH,
'notifications':{
'send_date' : 'now',
'content' : 'test',
'data' : {
'custom' : 'json data'
},
'link' : 'http://pushwoosh.com/'
}
}
the pushwoosh guide lists serveral of sample codes in Java,PHP,Ruby and so on.I am quite confused that pushwoosh doesn't provide the nodejs version,so I have to carry it out by myself.I use the 'http' module to send the request and the parameters and part of main codes is shown below
var bodyArgs =
{'application' : PW_APPLICATION,
'auth' : PW_AUTH,
'notifications':{
'send_date' : 'now',
'content' : 'test',
'data' : {
'custom' : 'json data'
},
'link' : 'http://pushwoosh.com/'
}
}
var bodyArgsArray = [];
for (var i in bodyArgs) {
if (bodyArgs.hasOwnProperty(i)) {
if(typeof bodyArgs[i] == 'object'){
bodyArgsArray.push(i + '=' + (JSON.stringify(bodyArgs[i])));
}else{
bodyArgsArray.push(i + '=' + (bodyArgs[i]));
}
}
}
var options = {
host: 'cp.pushwoosh.com',
method: 'POST',
path: '/json/1.3/createMessage',
headers: {'Content-Length': bodyStr.length,
'Content-Type':'application/json',
'Access-Control-Allow-Origin':'*'
}
var req = http.request(options, function (res){...});
unfortunately,I get the malformed response
[syntax error at end of input]
if the request is processed successfully, the correct response shoule be
{
"status_code":200,
"status_message":"OK",
"response": {
"Messages":["{Notification code}", "{Notification code}", ...]
}
}
I got a great desire to figure out the correct request format.I will be pretty appreciate of someone's nodejs version if possible!
And the pushwoosh remote-api-guide website is
https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/
I figured out how to get this working. You were really close
{ "request":{ "application":"APPLICATION_CODE", "applications_group":"GROUP_CODE", // Optional. Can be used instead of "application" "auth":"api_access_token", "notifications":[] }}
So the thing that got left off is that you need to wrap your json request in a object called "request" as you can see above. I am actually in the process of writing a node module to use pushwoosh. I thought I would post this in case anyone is looking for the answer. I will post the npm module name once I finish it but if you really want to get it working now that is all you have to do.
Hey i have written a node module to send push notifications to mobile devices with Pushwoosh API