@Baumgart wrote:
Hi Guys, I've been stuck on this for quite a while now. I am trying to reach the Ionic push API over node js, I will probably deploy the server on Heroku. I have been searching through a lot of forums now, but I couldn't find a good solution yet. There is a library for iOS which does what I found but for Android I haven't found anything.
If I paste my header, payload and the ionic url in Google's advanced rest client, I receive a message on my device. So my post parameteres seem to be okay.But running my node.js file gives me the following error:
{"result": "error", "message": "A list of tokens or user_ids is required"}
// node modules var request = require('request'); var Buffer = require('buffer').Buffer; // Ionic Access variables var privateKey = 'myKey'; var tokens = "myUsers tokens "; var appId = 'myAppId'; // encode the key var b = new Buffer(privateKey); var auth = b.toString('base64'); // post headers var headers = { 'Content-Type': 'application/json', 'X-Ionic-Application-Id': appId, 'Authorization': 'basic ' + auth }; var payload = { "tokens":[ tokens ], "notification":{ "alert": "Hello it is working!!", "ios":{ "badge":1, "sound":"ping.aiff", "expiry": 1423238641, "priority": 10, "contentAvailable": true, "payload":{ "key1":"value", "key2":"value" } }, "android":{ "collapseKey":"foo", "delayWhileIdle":true, "timeToLive":300, "payload":{ "key1":"value", "key2":"value" } } } }; // Configure the request var options = { url: 'https://push.ionic.io/api/v1/push', method: 'POST', headers: headers, form: payload }; // Start the request request(options, function (error, response, body) { console.log(body); if (!error && response.statusCode == 200) { // Print out the response body console.log(body) } });
Posts: 1
Participants: 1