08-12-2020 03:46 PM
We are using the REST Client element to call a service that returns JSON. I am trying to parse a JSON response where we have to use POST to call the service. It appears I am unable to parse the response. When I write the response to the activity log, there are not any commas between output fields. When I test with Postman, the response contains the commas. Would the REST Client element be stripping the commas off the response or do I have something incorrect when calling the service (screen shot of element below)? When I enter the response that is in the Activity log on http://jsonpath.com/, it errors until I add the commas between the output fields.
Activity Log:
{"GCS0558POperationResponse":{"gcs0558c_data":{"output_fields":{"excp_msg":"SUCCESSFUL ""excp_number":0"verified":"Y"}}}}
Postman:
Solved! Go to Solution.
08-13-2020 12:40 PM
Thanks David!
I forget about the debug functionality in Call Studio. Great idea to create a separate application to move code into for debugging.
The response body displays correctly with the commas in the debugger.
I finally determined my issue when trying to populate session variables from the Set Value element I was using to parse the response body. I was referencing Element Data, thinking the variables would be created there, instead of using the Local Variables.
08-12-2020 07:21 PM
I don't have a POST endpoint which returns any long JSON at my disposel, but I do have a GET which returns a massive JSON string and I see the commas. I did this through the same CVP Studio you're running. If you put that element in it's own application and do a debug session, do you see the right data in the debug? I'm wondering if the issue is with the write to log.
david
08-13-2020 11:05 AM - edited 08-13-2020 11:06 AM
Thanks David!
I forget about the debug functionality in Call Studio. Great idea to set up a separate debug application that I can move code in and out of.
The response body displays correctly with the commas when I debug the element. So my Set Value element is not parsing response correctly. Maybe I have the syntax incorrect? I verified the path displays the value using http://jsonpath.com/.
localProviderExcpMsg:
importPackage(com.audium.server.cvpUtil);
var jsonResponse = {Data.Element.Call_Provider_CICS_Service.response_body}
var path = "GCS0558POperationResponse.gcs0558c_data.output_fields.excp_msg"
var result = JSONPathUtil.eval(jsonResponse, path);
result //return the result of the JSONPathUtil.eval into the local variable.
localProviderExcpNumber:
importPackage(com.audium.server.cvpUtil);
var jsonResponse = {Data.Element.Call_Provider_CICS_Service.response_body}
var path = "GCS0558POperationResponse.gcs0558c_data.output_fields.excp_number"
var result = JSONPathUtil.eval(jsonResponse, path);
result //return the result of the JSONPathUtil.eval into the local variable.
localProviderVerified:
importPackage(com.audium.server.cvpUtil);
var jsonResponse = {Data.Element.Call_Provider_CICS_Service.response_body}
var path = "GCS0558POperationResponse.gcs0558c_data.output_fields.verified"
var result = JSONPathUtil.eval(jsonResponse, path);
result //return the result of the JSONPathUtil.eval into the local variable.
08-14-2020 03:11 AM
If you're still having issues with the parsing of the JSON this person seems to have had the exact same question as you. https://community.cisco.com/t5/contact-center/cvp-set-value-element-json-parse-array-child/td-p/3912467
david
08-14-2020 03:47 AM
Also maybe try this:
var jsonResponse = {Data.Element.Call_Provider_CICS_Service.response_body}
var path = "$.GCS0558POperationResponse.gcs0558c_data.output_fields.excp_msg"
var result = JSONPathUtil.eval(jsonResponse, path);
String(result);
david
08-13-2020 12:40 PM
Thanks David!
I forget about the debug functionality in Call Studio. Great idea to create a separate application to move code into for debugging.
The response body displays correctly with the commas in the debugger.
I finally determined my issue when trying to populate session variables from the Set Value element I was using to parse the response body. I was referencing Element Data, thinking the variables would be created there, instead of using the Local Variables.
08-13-2020 12:43 PM
Very glad you figured it out and yeah the debug functionality is pretty nice in Studio. I rarely use it, but should definitely spend more time with it as it makes testing so much faster.
david
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide