var registrationIds = [];
//Get RegistrationIDs for matching Chrome instances
registrationIds.push('ID1');
registrationIds.push('ID2');
//Make payload
var payload = {
"data.msgType": "desktopNotification",
"data.type": "basic",
"data.title": form.notificationTitle, //String
"data.message": form.notificationMessage, //String
"data.icon": form.notificationIcon, //String
"data.buttons": btnCfg, //Array instantiated previously
"data.links": linkCfg, //Array instantiated previously
"delay_while_idle": true,
"registration_ids": registrationIds //Array of registration IDs from above
};
//Make params
var params = {
"headers" : {
"Authorization" : "key=" + apiKey, //Set the API KEy
},
"contentType": "application/json", //Set content type to be JSON
"method": "post",
"payload": JSON.stringify(payload) //Stringify the payload
};
Logger.log(UrlFetchApp.getRequest(url, params)); //Debugging var response = UrlFetchApp.fetch(url, params); //Do submit
[15-04-19 22:14:06:048 EDT] {headers={Authorization=key=$APIKEY$}, useIntranet=false, followRedirects=true, payload={"data.msgType":"desktopNotification","data.type":"basic","data.title":"Important Message","data.message":"","data.icon":"Alert","data.buttons":[],"data.links":[],"delay_while_idle":true,"registration_ids":["ID1","ID2"]}, method=post, validateHttpsCertificates=true, contentType=application/json, url=https://android.googleapis.com/gcm/send}
[15-04-19 22:14:06:085 EDT] {failure=0, results=[{message_id=0:1429496046070775%fde00cbff9fd7ecd}, {message_id=0:1429496046070690%fde00cbff9fd7ecd}], success=2, multicast_id=7.1885521162196777E18, canonical_ids=0}
The first line is logging the raw message variable from the "hrome.gcm.onMessage.addListener(function(message) {})" listener. The second, empty object is message.data.
{ "data": {
"score": "5x1",
"time": "15:10"
},
"registration_ids": ["4", "8", "15", "16", "23", "42"]
}
//Make payload of data var payload = { "data": { "msgType": "desktopNotification", "type": "basic", "title": form.notificationTitle, "message": form.notificationMessage, "icon": form.notificationIcon, "buttons": btnCfg, "links": linkCfg }, "delay_while_idle": true, "registration_ids": registrationIds };
//Make params var params = { "headers" : { "Authorization" : "key=" + apiKey,
}, "method": "post", "payload": JSON.stringify(payload), "contentType": "application/json" };