There error you see relates to something in the pre-process script being None or undefined
I was able to replicate your script in "true python" below.
Original Message:
Sent: 02-15-2019 08:35 AM
From: Juan Cruz Del Col
Subject: Text Area Field in json
Shane, I had faith!
but I do not know why I have this error:
State: Anomalous
User: System User
Reason: An error occurred while processing the action acknowledgment. Additional information: Pre-processing script for Function 'Utilities: Call REST API' from Workflow 'AbrirPeticion' was unable to complete because: 'NoneType' object is unsubscriptable
Attached pre and post script
------------------------------
Juan Cruz Del Col
Original Message:
Sent: 02-15-2019 07:02 AM
From: Shane Curtin
Subject: Text Area Field in json
Try the following:
description1 = rule.properties.description['content']description1 = description1.replace(u'"', u'\\"')description1 = description1.replace(u"'", u"\\'")description1 = description1.replace(u'\\', u'\\\\')description1 = description1.replace(u'\n', u'\\n')description2 = u"{0}". format(unicode(description1))
------------------------------
Shane Curtin
Integrations Engineer - IBM Resilient
Original Message:
Sent: 02-14-2019 03:21 PM
From: Juan Cruz Del Col
Subject: Text Area Field in json
Shane, I have the problem with double quotes.
Do the following:
description1 = rule.properties.description ['content']description2 = u "{0}". format (unicode (description1))description3 = description2.replace ('\ "', '\\"')
The result is:
{ "ResilientQ": { "Categoria": "Seguridad", "Subcategoria": "Seguridad -- Antivirus -- Consulta", "GrupoAsignado": "SEGURIDAD-ANTIVIRUS", "SolicitadoPara": "falcon", "FechaRequerida": "2019-02-14T20:16:26", "SolicitadoPor": "falcon", "Descripcion": ["u'Estimados,\n\n \n\nMicrosoft lanz\xf3 actualizaciones de seguridad para algunos de sus productos, ya que se han descubierto diversas vulnerabilidades, la m\xe1s grave podr\xeda permitir la ejecuci\xf3n de c\xf3digo arbitrario en la m\xe1quina cliente.\n\n \n\nHasta el momento ninguna de las vulnerabilidades solucionadas, se est\xe1 explotando activamente. Dentro de las m\xe1s importantes, se encuentra la CVE-2019-0547 , una debilidad en el componente de Windows responsable de asignar direcciones de Internet a las computadoras host (tambi\xe9n conocido como \\"cliente DHCP de Windows\\"). \n\n \n\n \n\n \n\nProductos afectados:\n\n \n\n\u2022 Adobe Flash Player\n\n\u2022 Internet Explorer\n\n\u2022 Microsoft Edge\n\n\u2022 Microsoft Windows\n\n\u2022 Microsoft Office, Microsoft Office Services y aplicaciones web\n\n\u2022 ChakraCore\n\n\u2022 .NET Framework\n\n\u2022 Microsoft Dynamics NAV\n\n\u2022 Microsoft Exchange Server\n\n\u2022 Microsoft Visual Studio\n\n\u2022 Windows Azure Pack (WAP)\n\n \n\n \n\nActualizaciones a aplicar\n\nVer listado aqu\xed: https://portal.msrc.microsoft.com/en-us/security-guidance/summary\n\n \n\n \n\nRecomendaciones\n\nAplicar las actualizaciones de seguridad correspondientes, tomando en cuenta las ventanas de tiempo establecidas para las pruebas.'" ], "Titulo": "asd", "GrupoRegistradoPor": "SEGURIDAD-ANTIVIRUS", "Fase": "Registro" }}
My problem is in
\\ "Windows DHCP client \\"
should be
\"Windows DHCP client \"
------------------------------
Juan Cruz Del Col
Original Message:
Sent: 02-14-2019 03:29 AM
From: Shane Curtin
Subject: Text Area Field in json
Hi Juan,
If the function returns results that are of Type Unicode, you need to pay particular attention when concatenating "strings" together in the post-process script.
For example, we have a function that returns:
results = { "event_name": જ ઝ ઞ ટ ઠ ડ ઢ ણ ત થ દ }
and in our Workflow's post-process script, we want to append the event_name to the name of the incident. So we do the following:
custom_incident_name = u"{0} - {1}".format(unicode(results.event_name), unicode(incident.name))incident.name = custom_incident_name
Take note of how we "convert" everything to unicode when we want to concatenate.
Hope this helps!
------------------------------
Shane Curtin
Integrations Engineer - IBM Resilient
Original Message:
Sent: 02-13-2019 09:04 AM
From: Juan Cruz Del Col
Subject: Text Area Field in json
Romina, Romina, I would like to send a similar text to the attachment and it fails me, I have tried it in many ways and it always fails.
In the "Workflow status" error:
------------------------------
Juan Cruz Del Col
Original Message:
Sent: 02-06-2019 01:15 PM
From: Romina Jose
Subject: Text Area Field in json
I've asked Juan to try the following in the pre-process script:
description = rule.properties.description["content"]
inputs.description = """
{
"ResilientQ": {
"description": [""" + repr(description) + """ ],
}
}
"""
According to Juan, the above worked.
------------------------------
Romina Jose
Original Message:
Sent: 02-06-2019 09:39 AM
From: JOHN PRENDERGAST
Subject: Text Area Field in json
The description is not valid json and will throw and error. The characters you reference \ or / or " will need to to be escaped and newlines transformed as well . It will require a bespoke solution and as you specified using regex in the pre-processing script may be a possible option. The re module is available in the pre and post processing scripts so that could be used. Do you need help with a regex pattern?
------------------------------
JOHN PRENDERGAST
Original Message:
Sent: 02-05-2019 09:33 PM
From: Juan Cruz Del Col
Subject: Text Area Field in json
I have a problem using the "Call REST API" function
1- I add a field of type "text area" inside a rule (see image 1a.png and 1b.png)
2- Within the workflow I call a function called "Call REST API" and in the pre-script I refer to the field "description" created in point 1. (see image 2.png)
3- Then the verifiable "Description1" should be entered as part of the "inputs.rest_body" (see image 3.png)
4- Finally I will perform a test of the action "Abrir Peticion" that calls the workflow of point 3. Request that you complete the fields of point 1. As an example, enter text multi line (see image 4a.pgn and 4b.png )
As a result I get an error because I can not interpret the json (see image log.png)
The response of the rest:
2019-02-05 22:59:00,882 DEBUG [actions_component] Result: {'cookies': {}, 'links': {}, 'text': u'{\n "Messages": ["JSONException: Unterminated string at character 304"],\n "ReturnCode": "-5"\n}', 'elapsed': 61, 'apparent_encoding': 'ascii', 'reason': 'Bad Request', 'ok': False, 'url': u'http://10.4.0.14:25001/SM/9/rest/ResilientQ/', 'headers': {'Content-Length': '95', 'X-Content-Type-Options': 'nosniff', 'Keep-Alive': 'timeout=1200000, max=1000', 'Server': 'Apache-Coyote/1.1', 'Connection': 'Keep-Alive, close', 'Date': 'Wed, 06 Feb 2019 02:14:06 GMT', 'Content-Type': 'application/json;charset=utf-8'}, 'json': {u'ReturnCode': u'-5', u'Messages': [u'JSONException: Unterminated string at character 304']}, 'status_code': 400}
If the json be formed as follows this would work:
2019-02-05 22:59:00,307 INFO [utilities_call_rest_api] rest_body:
{
"ResilientQ": {
"Categoria": "Seguridad",
"Subcategoria": "Seguridad -- Antivirus -- Consulta",
"GrupoAsignado": "SEGURIDAD-ANTIVIRUS",
"SolicitadoPara": "falcon",
"FechaRequerida": "2019-02-28T03:00:00",
"SolicitadoPor": "falcon",
"Descripcion": ["Test of a text line 1\nTest of a text line 2\nTest of a text line 3\nTest of a text line 4"],
"Titulo": "Prueba",
"GrupoRegistradoPor": "SEGURIDAD-ANTIVIRUS",
"Fase": "Registro"
}
}
Another error occurs if the text has special characters such as \ or / or "
for example (see image 5.png), in the app.log:
2019-02-05 23:08:24,764 INFO [utilities_call_rest_api] rest_body:
{
"ResilientQ": {
"Categoria": "Seguridad",
"Subcategoria": "Seguridad -- Antivirus -- Consulta",
"GrupoAsignado": "SEGURIDAD-ANTIVIRUS",
"SolicitadoPara": "falcon",
"FechaRequerida": "2019-02-28T03:00:00",
"SolicitadoPor": "falcon",
"Descripcion": ["Test of a text "line" 1
Test of a text line 2
Test of a text \line\ 3
Test of a text /line"/ 4"],
"Titulo": "Prueba",
"GrupoRegistradoPor": "SEGURIDAD-ANTIVIRUS",
"Fase": "Registro"
}
}
2019-02-05 23:08:25,165 DEBUG [actions_component] Result: {'cookies': {}, 'links': {}, 'text': u'{\n "Messages": ["JSONException: Expected a \',\' or \']\' at character 299"],\n "ReturnCode": "-5"\n}', 'elapsed': 6, 'apparent_encoding': 'ascii', 'reason': 'Bad Request', 'ok': False, 'url': u'http://10.4.0.14:25001/SM/9/rest/ResilientQ/', 'headers': {'Content-Length': '97', 'X-Content-Type-Options': 'nosniff', 'Keep-Alive': 'timeout=1200000, max=1000', 'Server': 'Apache-Coyote/1.1', 'Connection': 'Keep-Alive, close', 'Date': 'Wed, 06 Feb 2019 02:23:34 GMT', 'Content-Type': 'application/json;charset=utf-8'}, 'json': {u'ReturnCode': u'-5', u'Messages': [u"JSONException: Expected a ',' or ']' at character 299"]}, 'status_code': 400}
Can you help me solve this problem? Maybe with some regular expression or replace we can do something.
Thank you!
------------------------------
Juan Cruz Del Col
------------------------------