- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 06:39 AM
REST API Call to 3rd party(AlgoSec) is giving BAD JSON Format response in ECC Queue:
The format I was told to use is one I'm unfamiliar with, however when trying to use their format I get the same JSON error. In the content section of the HTTP Method:
{
"template": "Standard",
"requestor":"${requestor}",
"change_request_justification":"${change_request_justification}",
"external_change_request":"${external_change_request}",
"traffic": [{ "source": {"items": [{ "name": ""}] },
"destination": {"items": [{ "name": "}] },
"service": {"items": [{"name": "" }] },
"action": "Allow",
"application": {"items": [{"name": ""}]} }]
}
"Traffic" seems to be the equivalent to a MRVS we have in SNOW to pass over to AlgoSec.
Here is the Run Script POST in my workflow:
try {
var r = new sn_ws.RESTMessageV2('AlgoSec', 'AlgoSec POST');
r.setRequestHeader('Cookie',current.variables.sessionid.toString());
r.setStringParameterNoEscape('template', 'Standard');
r.setStringParameterNoEscape('requestor', current.variables.requester_name.getDisplayValue());
r.setStringParameterNoEscape('change request justification',current.variables.chg_justification);
r.setStringParameterNoEscape('external change request id', current.number);
r.setStringParameterNoEscape('traffic', current.variables.access_request_detail);
r.setStringParameterNoEscape('action', 'Allow');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
current.variables.xml_response = responseBody;
I authenticate correctly, then the POST happens and I get the below back in the ECC queue input:
<results error="Method failed: (/FireFlow/api/change-requests/traffic) with code: 400" probe_time="209" result_code="900000">
<result error="Method failed: (/FireFlow/api/change-requests/traffic) with code: 400">
<output>{"status":"Failure","messages":[{"code":"BAD_JSON_FORMAT","message":"Bad JSON format: failed to parse request body"}],"data":null}</output>
</result>
Response content:
"content" value="{ "template": "Standard", "requestor":"Jeffrey Booher", "change_request_justification":"", "external_change_request":"", "traffic": [{ "source": {"items": [{ "name": ""}] }, "destination": {"items": [{ "name": "}] }, "service": {"items": [{"name": "" }] }, "action": "Allow", "application": {"items": [{"name": ""}]} }] }"/>
I'm assuming the format I'm using in the Content of the HTTP Method and the Run Script POST in the workflow are not formatted correctly, so any pointers would be great.
Typically when passing MRVs I use "name_of_mrvs":${name_of_mrvs} and the variables I use "name_of_var":"${name_of_var}",
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 08:14 AM
Hello @booher04
It's because you are calling the rest message function outside the loop. It's having only first initialized value, that's why working for only one.
Please use below 👇 script -
var mrvs = current.variables.access_request_detail;
var rowCount = mrvs.getRowCount();
// Function to send REST request
function sendRestRequest(dest, sourceIp, destIp) {
try {
var r = new sn_ws.RESTMessageV2('AlgoSec', 'AlgoSec POST');
r.setRequestHeader('Cookie', current.variables.sessionid.toString());
r.setStringParameterNoEscape('service', dest);
r.setStringParameterNoEscape('application', "any");
r.setStringParameterNoEscape('source', sourceIp);
r.setStringParameterNoEscape('destination', destIp);
var response = r.execute();
gs.info('Request body: ' + r.getRequestBody());
return response.getBody();
} catch (ex) {
gs.error('REST request failed: ' + ex.message);
return null;
}
}
// Loop through the MRVS contents
var responseBody = '';
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
var dest = row.destination_tcp_port;
var sourceIp = row.source_ip_address_es;
var destIp = row.destination_ip_address_es;
responseBody = sendRestRequest(dest, sourceIp, destIp);
}
// Store the last response in the variable
current.variables.xml_response = responseBody;
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 08:06 AM
03-21-2025 11:04:04 AM | system | Information | AlgoSec API HTTP Status: 400 | *** Script | |
Select record for action: Created 03-21-2025 11:04:04 AM | 03-21-2025 11:04:04 AM | system | Information | AlgoSec API Response: {"status":"Failure","messages":[{"code":"BAD_JSON_FORMAT","message":"Bad JSON format: failed to parse request body"}],"data":null} |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 08:09 AM
Hello @booher04
In that case, are you sure that the field names that you have passed in the json are correct ? There is no naming convention error ?
Also the header Content is set to Application/Json ? Accept also set to same ?
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 08:17 AM
I removed the 2 fields that would be outside of the MRVs(except for requestor because it's working). I got the below input from AlgoSec in ECC:
<results error="Method failed: (/FireFlow/api/change-requests/traffic) with code: 400" probe_time="482" result_code="900000">
<result error="Method failed: (/FireFlow/api/change-requests/traffic) with code: 400">
<output>{"status":"Failure","messages":[{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"source field contains invalid value(s): Null (traffic line 1)"},{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"destination field contains invalid value(s): Null (traffic line 1)"},{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"service field contains invalid value(s): Null (traffic line 1)"},{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"application field contains invalid value(s): Null (traffic line 1)"}],"data":null}</output>
</result>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 08:26 AM
Hello @booher04
It means, you are passing some values to choice field or reference fields which do not already exist on your table.
Please cross check all the field names and values that you are passing. Everything should be valid and correct. Along with the script already provided above.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 07:45 AM
Content format they require:
{
"template": "Standard",
"traffic": [
{
"source": {
"items": [
{
"address": "${source}"
}
]
},
"destination": {
"items": [
{
"address": "${destination}"
}
]
},
"service": {
"items": [
{
"address": "${service}"
}
]
},
"application": {
"items": [
{
"name": "${application}"
}
]
},
"action": "Allow"
}
]
}
Here's my POST in the workflow:
try {
var r = new sn_ws.RESTMessageV2('AlgoSec', 'AlgoSec POST');
r.setRequestHeader('Cookie',current.variables.sessionid.toString());
r.setStringParameterNoEscape('template', 'Standard');
//r.setStringParameterNoEscape('traffic', current.variables.access_request_detail);
//r.setStringParameterNoEscape('action', 'Allow');
r.setStringParameterNoEscape('service', current.variables.access_request_detail.destination_tcp_port);
r.setStringParameterNoEscape('application', current.variables.application_variable.getDisplayValue());
r.setStringParameterNoEscape('source',current.variables.access_request_detail.source_ip_address_es);
r.setStringParameterNoEscape('destination', current.variables.access_request_detail.destination_ip_address_es);
//r.setStringParameterNoEscape('content',global.JSON.stringify(jsonObj));
var response = r.execute();
gs.info('Request body' + r.getRequestBody());
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
current.variables.xml_response = responseBody;
Here's the error I receive now:
<result error="Method failed: (/FireFlow/api/change-requests/traffic) with code: 400">
<output>{"status":"Failure","messages":[{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"source field contains invalid value(s): [[1.1.1.12]] (traffic line 1)"},{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"destination field contains invalid value(s): [[2.2.2.2]] (traffic line 1)"},{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"service field contains invalid value(s): [[22]] (traffic line 1)"},{"code":"INVALID_VALUE_FOR_FIELD_IN_LINE","message":"application field contains invalid value(s): [Accounting Imaging [UAT]] (traffic line 1)"}],"data":null}</output>
</result>