Sending HTTP requests to store special characters‽
We would like to be able to store accented characters into an API.
Currently our Rest Operation is the following:
{ Parameter INVOCATION = "Queue"; Method CrearNotificacion(pRequest As Mensajes.Request.NotificacionesPUSH.CrearNotificacion, pResponse As Mensajes.Response.NotificacionesPUSH.CrearNotificacion) As %Library.Status
{
Set body = {
"app_id": (pRequest.idApp),
"headings": {"en":(pRequest.notificacion.titulo),"es":(pRequest.notificacion.titulo)},
"subtitle": {"en":(pRequest.notificacion.subtitulo),"es":(pRequest.notificacion.subtitulo)},
"contents": {"en":(pRequest.notificacion.mensaje),"es":(pRequest.notificacion.mensaje)},
"data":(^data),
"include_player_ids": (^idsDispositivos)
}
set httpRequest = ##class(%Net.HttpRequest).%New()
set tResponse = ##class(%Net.HttpResponse).%New()
set httpRequest.Server = "onesignal.com"
set httpRequest.ContentType = "application/json"
set httpRequest.Authorization = "Basic "_##class(Util.TablasMaestras).getValorMaestra("NOTIFICACIONESPUSH.PARAMETRIZACIONES","ONESIGNAL_APIKEY_SCS")
set httpRequest.Https = 1 set httpRequest.SSLConfiguration = "Certificado_SCS"
set dataObject = ##class(%DynamicObject).%FromJSON(body.data)
set body.data = dataObject $$$LOGINFO("body.'include_player_ids': "_body."include_player_ids")
set idsDispositivosObject = ##class(%DynamicObject).%FromJSON(body."include_player_ids")
set body."include_player_ids" = idsDispositivosObject //set status =
Do httpRequest.EntityBody.Write(body.%ToJSON()) while(httpRequest.EntityBody.AtEnd=0){
set linea = httpRequest.EntityBody.Read()
}
$$$LOGINFO("linea: "_linea)
set tSC = httpRequest.Post("https://onesignal.com/api/v1/notifications") set tResponse = httpRequest.HttpResponse
if $$$ISERR(tSC){
$$$ThrowOnError(tSC)
}
if (tResponse.Data.AtEnd = 0) {
set linea = tResponse.Data.Read()
} set pResponse = ##class(Mensajes.Response.NotificacionesPUSH.CrearNotificacion).%New()
do pResponse.informacion.Write(linea) Quit pResponse
} XData MessageMap
{
<MapItems>
<MapItem MessageType="Mensajes.Request.NotificacionesPUSH.CrearNotificacion">
<Method>CrearNotificacion</Method>
</MapItem>
</MapItems>
} }
We have read:
https://community.intersystems.com/post/managing-utf-8-characters-databa...
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
We have tried to use:
And even we tried to convert the headings itself:
Currently we see that our operation's LOGINFO let's us see that the JSON contains the accented character, in this case an "'ó"
However when we view the notification stored in the API it shows as a strange character:
Besides we have checked that if we send a create notification request dirctly from SoapUI, it is been stored with strange characters too:
--> However if we set the Encoding to UTF-8 in SoapUI, it is being stored correctly:
So then, we would like to change the charset to utf-8 in Ensemble.
If we try:
The API does not recognize the Content-Type: application/json
We have also read:
https://stackoverflow.com/questions/17154967/is-content-encoding-being-s...
How could we send HTTP requests to store special characters‽