I'm trying to create a User Notification group on Google Cloud Messaging using a Google Apps Script server. I'm following directions here:http://developer.android.com/google/gcm/notifications.html
I'm getting the following error:
Request failed for https://android.googleapis.com/gcm/notification returned code 400. Truncated server response: {"error":"NOT_A_JSON_REQUEST"} (use muteHttpExceptions option to examine full response) (line 86, file "Code")
function SetUserNotification(data) {
var url = "https://android.googleapis.com/gcm/notification";
var apiKey = "<MyApiKey>";
var projectID = "<MyProjectId>";
var registrationId = data[2];
var headers = {
"Content-Type": "application/json",
"project_id": projectID,
"Authorization": "key=" + apiKey
};
var payload = {
"operation": "create",
"notification_key_name": "ST-User" + data[3],
"registration_ids": registrationId
};
var params = {
headers: headers,
method: "post",
payload: payload
};
var response = UrlFetchApp.fetch(url, params);
Logger.log("response = " + response.getContentText());
return {message: "send completed: " + response.getContentText()};
}
What am I doing wrong? I can't find any examples of creating a notification key online, just what seems to be incomplete instructions.
Update: Here's the execution transcript from the fetch function. Note line 87 is the fetch call.
[15-01-25 21:55:11:877 EST] UrlFetchApp.fetch([https://android.googleapis.com/gcm/notification, {headers={Authorization=key=MYAUTHKEY, project_id=MYPROJID, Content-Type=application/json}, payload={"operation":"create","notification_key_name":"ST-User1","registration_ids":"[abcdefgblahblah]"}, method=post}]) [0.015 seconds]
[15-01-25 21:55:11:879 EST] Execution failed: Request failed for https://android.googleapis.com/gcm/notification returned code 400. Truncated server response: {"error":"NOT_A_JSON_REQUEST"} (use muteHttpExceptions option to examine full response) (line 87, file "Code") [0.019 seconds total runtime]
"registration_ids": ["4"]
– Alan Wellsheaders
,method
andpayload
in double quotes, and see if that makes a difference."headers": headers, etc
– Alan Wells