- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2015 01:05 PM
Trying to run a RESST API command. When in the REST setup all is working correctly.
However, once I set up to use this from a script in the Change Workflow it is erroring.
The following script is what I get on the preview of the REST obect in the post method:
try {
var r = new sn_ws.RESTMessageV2('Nolio Deployment', 'post');
r.setStringParameter('deployment', '"CHG1111112-Fri April 29 14:00:00 CST 2015"');
r.setStringParameter('project', '"SNOWTest"');
r.setStringParameter('build', '"1.0.0"');
r.setStringParameter('application', '"Tomcat Generic"');
r.setStringParameter('environments', '["Environment for Default Architecture"]');
r.setStringParameter('deploymentPlan', '"Ken Prior"');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.getMessage();
}
However, this same script is failing with the following when doing this from a run script in the workflow with the following error:
{"result":false,"description":"Could not read JSON: Unexpected character ('&' (code 38)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1b92a907; line: 1, column: 18]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('&' (code 38)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1b92a907; line: 1, column: 18]"}
Any help would be appreciated.
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2015 12:26 PM
I had to change my call to NoEscape in my case.
try {
var r = new sn_ws.RESTMessageV2('Nolio Deployment', 'post');
r.setStringParameterNoEscape('application', '"' + current.u_app + '"');
r.setStringParameterNoEscape('build', '"' + current.u_build + '"');
r.setStringParameterNoEscape('project', '"' + current.u_nolio_project + '"');
r.setStringParameterNoEscape('deploymentPlan', '"' + current.u_deployment_plan + '"');
r.setStringParameterNoEscape('environments', '["' + current.u_environments + '"]');
r.setStringParameterNoEscape('deployment', '"' + current.u_deployment + '"');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
current.u_nolio_results = "Result: " + parsed.result + String.fromCharCode(13) + "Description: " + parsed.description + String.fromCharCode(13);
}
catch(ex) {
var message = ex.getMessage();
}
Thanks all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2015 03:08 PM
I'm taking a guess here, but I think the error is with trying to add multiple string parameters. I would try building the JSON string and running it as a parameter for execute. Like this:
var postString = "{\"deployment\":\"CHG1111112-Fri April 29 14:00:00 CST 2015\", \"project\":\"SNOWTest\", \"build\":\"1.0.0\", \"application\":\"Tomcat Generic\",\"environments\", \"[\\"Environment for Default Architecture\\"]\", \"deploymentPlan\":\"Ken Prior\"}";
var response = r.execute(postString);
I don't have experience running REST commands from workflows, but I use this method regularly to post from external apps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2015 06:28 AM
Thanks this failed to even pass the Script checker. :>)
Thanks for trying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2015 07:54 AM
Looks like it was hitting an error when I was trying to escape the quotation marks in the value for "environments". Here, this passes the syntax check:
var postString = "{\"deployment\":\"CHG1111112-Fri April 29 14:00:00 CST 2015\", \"project\":\"SNOWTest\", \"build\":\"1.0.0\", \"application\":\"Tomcat Generic\",\"environments\":\"[\\\"Environment for Default Architecture\\\"]\", \"deploymentPlan\":\"Ken Prior\"}";
var response = r.execute(postString);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2015 09:52 AM
Hi Kenneth,
It looks like the error is being returned form the external web service because it doesn't like what you sending. You should check what you have configured for this Outbound REST message to see what you have as the content. from the error it seems to be complaining about an "&" character
{"result":false,"description":"Could not read JSON: Unexpected character ('&' (code 38)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1b92a907; line: 1, column: 18]
Hope this helps.
-Jose