cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1941
Views
0
Helpful
6
Replies

REST Element in CVP Call Studio 11.6 - Commas stripped out of the JSON response body

lisa.ferraro
Level 1
Level 1

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:

{
    "GCS0558POperationResponse": {
        "gcs0558c_data": {
            "output_fields": {
                "excp_msg""SUCCESSFUL                                                                                                              ",
                "excp_number"0,
                "verified""Y"
            }
        }
    }
}
 
Capture.PNG
1 Accepted Solution

Accepted Solutions

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. 

 

View solution in original post

6 Replies 6

david.macias
VIP Alumni
VIP Alumni

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

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/.

 

Capture1.PNG

 

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.

 

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

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

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. 

 

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