- 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 07:33 AM
Hello @booher04
Please try below Json -
{
"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": ""
}
]
}
}
]
}
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 07:35 AM
Hello @booher04
A better way to view it -
{
"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": ""}]} }]
}
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 07:42 AM
Hello - thanks for the response. I get the same error message when using what you provided.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 07:50 AM
Hello @booher04
Try below with above -
try {
var r = new sn_ws.RESTMessageV2('AlgoSec', 'AlgoSec POST');
// Set request header
r.setRequestHeader('Cookie', current.variables.sessionid.toString());
// Ensure parameter names match API expectations
r.setStringParameterNoEscape('template', 'Standard');
// Check if requester_name is a reference field before using getDisplayValue()
var requesterName = current.variables.requester_name ? current.variables.requester_name.getDisplayValue() : '';
r.setStringParameterNoEscape('requestor', requesterName);
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();
// Log for debugging
gs.info("AlgoSec API Response: " + responseBody);
gs.info("AlgoSec API HTTP Status: " + httpStatus);
}
catch(ex) {
var message = ex.message;
gs.error("AlgoSec API Error: " + message);
var responseBody = "Error: " + message; // Ensure responseBody is always defined
}
// Store response in a variable for later use
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