- 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 06:14 AM
So It looks like the issue is being caused by the MRVs. It's passing the values but putting them in [ ]. I need to pass the values without the [ ] around them. I assume I'd need to somehow convert them to JSON and then pass the variables? Below you can see "22" is inside brackets and I need that to pass without the brackets.
"service": {
"items": [
{
"address": "[22]"
}
]
},
try {
var r = new sn_ws.RESTMessageV2('AlgoSec', 'AlgoSec POST');
r.setRequestHeader('Cookie',current.variables.sessionid.toString());
r.setStringParameterNoEscape('service', current.variables.access_request_detail.destination_tcp_port);
r.setStringParameterNoEscape('application', "any");
r.setStringParameterNoEscape('source',current.variables.access_request_detail.source_ip_address_es);
r.setStringParameterNoEscape('destination', current.variables.access_request_detail.destination_ip_address_es);
var response = r.execute();
gs.info('Request body' + r.getRequestBody());
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 06:21 AM
Hello @booher04
I can very well see them as json objects only. See there is service json object and within it there is an array and within array another json object.
So you are saying you didn't intend it to pass that way and still it somehow passed like that?
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 06:25 AM
Our 3rd party vendor explained that the [ ] are the reason the POST is returning an invalid value. I believe it's being passed that way because it's within a MRVs? I created test variables outside of the MRVs and they passed without issue however, the customer explained they need it within a MRVs because of needing to send multiple records at a time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 06:33 AM
Hello @booher04
Actually the reason is valid, it will throw errors when getting array instead of json. So, now I am getting, the story here is they are having only JSON objects to be acceptable and since you are using MRVS, you are intending to post multiple records at one time which isn't feasible. There POST method is only made to take singular json objects.
This is similar to the query I answered yesterday on community. So what you can do is using for loop in your MRVS array and keep separating the json objects and then calling the post method in REST Message V2 function .
Yes, that would work.
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 07:57 AM
var mrvs = current.variables.access_request_detail;
var rowCount = mrvs.getRowCount();
//loop through the MRVS contents
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;
}
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());
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
current.variables.xml_response = responseBody;
So, I got this setup and it's sending correctly, however it's not sending multiple rows if I add 2 or more to the MRVs. Any idea what I am missing on this?