Question
· Nov 12, 2019

REST API outputs SSL Configuration error‽

Hello good afternoon!

We're testing a REST Operation, to View Devices using OneSignal API

We are sending the request from Production's Operation Test tool, using the following code:

What happens is that it tells us error of SSL Configuration:
 


 

It should be noted that the test was done without https, to:

set path = http://onesignal.com/api/v1/players?app_id=...

If we see the trace of the browser, we get that OneSignal when receiving an HTTP request, redirects it to HTTPS:

Receives HTTP, redirects:

to HTTPS:


With what we have written, we get an empty answer (the 1st redirection) and an SSL error (the 2nd request)


 

If we try the URL without the s, it doesn't even connect:
 

https://onesignal.com/api/v1/players?app_id=...

 


 

Since we don't get an answer
 


 

We also tried the certificate, but it gives us the same result.
 

We have already tried with POSTMAN, and it does answer to us:

The answer:

{
    "total_count": 4,
    "offset": 0,
    "limit": 300,
    "players": [
        {
            "id": "...",
            "identifier": "...",
            "session_count": 1,
            "language": null,
            "timezone": null,
            "game_version": null,
            "device_os": null,
            "device_type": 11,
            "device_model": null,
            "ad_id": null,
            "tags": {},
            "last_active": 0,
            "playtime": 0,
            "amount_spent": 0.0,
            "created_at": 1572890827,
            "invalid_identifier": false,
            "badge_count": 0,
            "sdk": null,
            "test_type": null,
            "ip": null,
            "external_user_id": null
        },
      ...
    ]
}
 

Do you have some kind of advice or way to better understand this behaviour

I have also read:

https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?K...

https://community.intersystems.com/post/seeking-clarification-between-re...
 

Finally I include all the code being discussed:

 

Class Operaciones.REST.NotificacionesPUSH.VerDispositivos Extends Ens.BusinessOperation
{
Parameter ADAPTER = "EnsLib.HTTP.OutboundAdapter";
Parameter INVOCATION = "Queue";
Method VerDispositivos(pRequest As Mensajes.Request.NotificacionesPUSH.VerDispositivos, pResponse As Ens.Response) As %Library.Status
{
set httpRequest = ##class(%Net.HttpRequest).%New()
set tResponse = ##class(%Net.HttpResponse).%New()
set httpRequest.ContentType = "application/json"

do httpRequest.AuthorizationSet("Basic ...")
set path = "..."

 


set tSC = httpRequest.Get(path)
set tResponse = httpRequest.HttpResponse
$$$LOGINFO("tResponse: "_httpRequest.HttpResponse.Data)
$$$LOGINFO("Antes")
While (tResponse.Data.AtEnd = 0) {
set respuesta = tResponse.Data.Read()
$$$LOGINFO("Respuesta: "_respuesta)
}
$$$LOGINFO("Despues")
$$$LOGINFO("Status: "_tSC)
Quit tSC
}
XData MessageMap
{
VerDispositivos }
}

 

Thanks for your help!

 

 

 


 

Discussion (1)1
Log in or sign up to continue

You need to generate a SSL configuration and provide to your request object by using the SSLConfiguration property, after this you must also inform to your request that you want to use a secure connection by enabling the property Https.

Here's how we send a push using OneSignal:

 set client = ##class(%Net.HttpRequest).%New()
 set client.Server = "onesignal.com"

 // You'll need to generate the configuration to be used below, you can decide its name.
 set client.SSLConfiguration = "OneSignal SSL Config"

 set client.Https = 1
 set client.Authorization = $$$FormatText("Basic %1", $get(^App.Envs("ONESIGNAL_KEY")))
 set client.ContentCharset = "utf-8"
 set client.ContentType = "application/json"
 set client.ContentEncoding = "utf-8"
 set client.NoDefaultContentCharset = 0

 set body = {
   "app_id": ($get(^App.Envs("ONESIGNAL_APPID"))),
   "data": (data),
   "contents": {
       "en": (message),
       "pt": (message)
   },
    "filters": (filters)
}

  set json = body.%ToJSON()
  do client.EntityBody.Write(json)

  set sc = client.Post("/api/v1/notifications")
  return sc

You can generate that SSL configuration using the portal, you can also something like this:

ClassMethod CreateSSLConfigurationIfNoneExists(name As %String)
{
   new $namespace
   set $namespace = "%SYS"

   do ##class(Security.SSLConfigs).Get(name, .p)
   if $data(p) quit   

   set p("CipherList")="ALL:!aNULL:!eNULL:!EXP:!SSLv2"
   set p("CAFile")=""
   set p("CAPath")=""
   set p("CRLFile")=""
   set p("CertificateFile")=""
   set p("CipherList")="ALL:!aNULL:!eNULL:!EXP:!SSLv2"
   set p("Description")=""
   set p("Enabled")=1
   set p("PrivateKeyFile")=""
   set p("PrivateKeyPassword")=""
   set p("PrivateKeyType")=2
   set p("Protocols")=24
   set p("SNIName")=""
   set p("Type")=0
   set p("VerifyDepth")=9
   set p("VerifyPeer")=0

   do ##class(Security.SSLConfigs).Create(name, .p)
}