The issue is the extra Content-Type header in the headers you're passing in. The content type is actually the fourth parameter of the http.request, and you're already passing in application/json there, which is correct. If you remove the Content-Type header definition, it should work fine.
When I try HTTPS request to OneSignal I got "CloudScriptHTTPRequestError" with this error.
Cloud code
var headers = {};
headers["Authorization"] = "Basic ************************************************";
headers["Content-Type"] = "application/json";
http.request('https://onesignal.com/api/v1/notifications', 'post', JSON.stringify(args), 'application/json', headers);
{
"code": 200,
"status": "OK",
"data": {
"FunctionName": "SendPushNotification",
"Revision": 11,
"Logs": [
{
"Level": "Error",
"Message": "HTTP request error",
"Data": {
"url": "https://onesignal.com/api/v1/notifications",
"method": "post",
"content": "{\"app_id\":\"********-****-****-****-************\",\"included_segments\":[\"All\"],\"contents\":{\"en\":\"English Message\"}}",
"contentType": "application/json",
"headers": {
"Authorization": "Basic ************************************************",
"Content-Type": "application/json"
},
"result": {
"responseContent": null,
"httpStatus": null,
"httpStatusCode": 0,
"requestError": "InternalError"
},
"httpRequestError": "InternalError"
}
}
],
"ExecutionTimeSeconds": 0.005013,
"ProcessorTimeSeconds": 0.016,
"MemoryConsumedBytes": 127864,
"APIRequestsIssued": 0,
"HttpRequestsIssued": 1,
"Error": {
"Error": "CloudScriptHTTPRequestError",
"Message": "The script made an external HTTP request, which returned an error. See the Error logs for details.",
"StackTrace": "Error\n at handlers.SendPushNotification (4D0A-main.js:37:7)"
}
},
"CallBackTimeMS": 607
}
Am I wrong?
Can you log the full response coming back from the call to http.request? Also, what is your Title ID?
This is full respoense
{
"code": 200,
"status": "OK",
"data": {
"FunctionName": "SendPushNotification",
"Revision": 38,
"Logs": [
{
"Level": "Error",
"Message": "HTTP request error",
"Data": {
"url": "https://onesignal.com/api/v1/notifications",
"method": "post",
"content": "{\"app_id\":\"{
{removed}}\",\"included_segments\":[\"All\"],\"contents\":{\"en\":\"English Message\"}}",
"contentType": "application/json",
"headers": {
"Authorization": "Basic {
{removed}}",
"Content-Type": "application/json"
},
"result": {
"responseContent": null,
"httpStatus": null,
"httpStatusCode": 0,
"requestError": "InternalError"
},
"httpRequestError": "InternalError"
}
}
],
"ExecutionTimeSeconds": 0.006567399999999999,
"ProcessorTimeSeconds": 0,
"MemoryConsumedBytes": 127808,
"APIRequestsIssued": 0,
"HttpRequestsIssued": 1,
"Error": {
"Error": "CloudScriptHTTPRequestError",
"Message": "The script made an external HTTP request, which returned an error. See the Error logs for details.",
"StackTrace": "Error\n at handlers.SendPushNotification (F8B8-main.js:36:7)"
}
},
"CallBackTimeMS": 482
}
and my TitleID is "F8B8"
1 Person is following this question.