- 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-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-25-2025 08:50 AM
Unfortunately this sent only 1 as well. It sent the 2nd entry and not the 1st.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 08:54 AM
Hello @booher04
No it has sent both.
Actually the response body that you are retrieving is the last one.
Please see my second message where I asked you to receive list of response. Because there won't be one response body, there will be multiple. So rest assured this has been sent.
If you want list of response body -
Use this code towards the end -
var responses = [];
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;
var response = sendRestRequest(dest, sourceIp, destIp);
responses.push(response);
}
// Store all responses as a concatenated string
current.variables.xml_response = responses.join(' || ');
You can check with other side. I am sure it's sent.
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-25-2025 11:13 AM
Thank you! I was able to get it working with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 11:17 AM
Hello @booher04
Great that whole this troubleshooting finally worked for you.
I would suggest please mark my all the messages which have sequence of scripts that worked correctly required for your question as solution. This will help anybody who visits this question, cause I feel it's a very comprehensive question and learning is a lot. But the message trail is just too big to go through. So if you mark all the correct scripts as solution, it will be really helpful for future readers.
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