Skip to content

Instantly share code, notes, and snippets.

@randymxj
Last active July 10, 2016 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randymxj/d000341be053425a4c243bf3b73e5e90 to your computer and use it in GitHub Desktop.
Save randymxj/d000341be053425a4c243bf3b73e5e90 to your computer and use it in GitHub Desktop.
Node.js request sending downstream POST with Google Firebase Cloud Message
/*
Example of Node.JS to send downstream cloud message with Firebase
NPM package request is needed in this code gist
*/
// Firebase auth key
var serverKey = "Firebase Server Key";
var clientToken= "Client Device Token"
// Payload message data
var deviceId = req.query.deviceId;
var eventName = req.query.eventName;
var value = req.query.value;
var options = {
url: 'https://fcm.googleapis.com/fcm/send',
headers: {
'Authorization': 'key=' + serverKey
},
json: {
"to": clientToken,
"data": {
deviceId: deviceId,
eventName: eventName,
value: value
}
}
};
request.post(options, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('ERROR - FIREBASE POST failed:', err);
}
// Success
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment