Trying to reach Ionic Push Api with Node.js (Android)

For anyone out there I’ve got it to work with the following:

// node modules
var http = require(‘http’);
var Buffer = require(‘buffer’).Buffer;
var inspect = require(‘eyespect’).inspector();

// Ionic Access variables
var privateKey = ‘myKey’;
var tokens = deviceToken’;
var appId = ‘appId’;

// encode the key
var b = new Buffer(privateKey);
var auth = b.toString(‘base64’);

// notification information
var payload = {
“tokens”:[
tokens
],
“notification”:{
“alert”: “Hello Marvin!”,
“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”
}
}
}
};

// convert payload to json
var body = JSON.stringify(
payload
);

// send request
var request = new http.ClientRequest({
hostname: “push.ionic.io”,
port: 80,
path: “/api/v1/push”,
method: “POST”,
headers: {
“Content-Type”: “application/json”,
‘X-Ionic-Application-Id’: appId,
‘Authorization’: 'basic ’ + auth,
“Content-Length”: Buffer.byteLength(body)
}
});
request.end(body);

// log response message
request.on(‘response’, function (response) {
var data = ‘’;

response.on(‘data’, function (chunk) {
data += chunk;
});

response.on(‘end’, function(){
inspect(data, ‘message’);
});
});