question

crik1981@gmail.com avatar image
crik1981@gmail.com asked

When I try HTTPS request I got "CloudScriptHTTPRequestError".

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

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.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crik1981@gmail.com avatar image crik1981@gmail.com commented ·

Thanks Brendan.

It's working :)

0 Likes 0 ·
crik1981@gmail.com avatar image
crik1981@gmail.com answered

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);

API Call Results

{
 "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?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Can you log the full response coming back from the call to http.request? Also, what is your Title ID?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crik1981@gmail.com avatar image crik1981@gmail.com commented ·

Can't add comment.

I posted log and TitleID down below.

0 Likes 0 ·
crik1981@gmail.com avatar image
crik1981@gmail.com answered

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"

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.