cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4508
Views
10
Helpful
8
Replies

UCCX REST/JSON Parsing Fail

e.silva
Level 1
Level 1

Hi,

 

I'm new using REST/JSON in UCCX,

My question is about parsing the REST response to a local UCCX variable

 

This is the response for the REST POST

TEXT[{\"response\":{\"pdTotalAmount\":"13705.12"}}]

 

Then I'm using the GetJSON Document Data with this JSON Path "$.pdTotalAmount"

But in the Result Data get null value

 

Attached a screenshot for the config

 

I'm missing something?

 

Thanks

8 Replies 8

Anthony Holloway
Cisco Employee
Cisco Employee

I highly recommend testing your JSON Paths before getting into UCCX, as UCCX is not the best at explaining to you what you did wrong.

 

I use this site:

http://jsonpath.com/

 

So, based on the testing, it looks like your JSON Path is in fact returning no results.

 

uccx-json-invalid-path.png

 

If we look at the structure of your JSON object, and the Path you chose, we can see that the pdTotalAmount node is not at the root level, but rather inside the response node, as a child.

 

Therefore, you're new JSON Path should be:

 

$.response.pdTotalAmount

uccx-json-valid-path.png

 

Bonus Tip

If you are sure that pdTotalAmount will be unique in the document structure, then you could just use the wildcard *, to search for it, in the entire document, without having to specify the entire path to it.

 

*.pdTotalAmount

You can read/learn more about JSON Path here:

https://www.pluralsight.com/blog/tutorials/introduction-to-jsonpath

Thanks a lot Anthony. 

The jsonon Path that you recomend worked. It send me the value I want. 

 

this is the $.response.pdSaldoTotal

 

when I try to add this value to the cisco iccx script editor I get an Document error.

Please see attached files. 

 

I get a document exception and the value of the GetJsonDocumentData its not stored in my Variable. 

 

the Variable that will store the value is called saldo and is type string and the JsonNotifyresponse variable  is type document.

 

Do you know how can I store the value in a variable. ?

 

Best Regards and thanks for your help.

 

 

Here is the jshon path:

I'm not sure what your problem is. Can you create a new script with only the steps necessary to recreate the problem? And also, can you share the error you are getting?

The most obvious thing I see is that in your JSON Document literal, you are escaping some, but not all double quotes.

I just made a sample script for you, to see if this works in 11.6, and I was successful.  See if you can replicate what I'm doing from the below screenshot, in your system.

 

uccx-json-float.png

Ok. Thanks

Let me do the test

Hi Anthony,

 

We already did some tests and we detect this difference in the http_response

Customer WebService Response:

TEXT[{\"response\":{\"pdSaldoTotal\":188904.34}}]

 

With your example the response is:

TEXT[{\"response\":{\"pdSaldoTotal\":\"188904.34\"}}]

 

In your http_response you are adding these characters \"

 

Attached is the error that UCCX is displaying

 

Thanks

 

Hi Anthony,

 

We just change the variable type from string to float and works. -)

 

In other web service, this is the response.

TEXT[{\"response\":{\"TSaldoA\":{\"TSaldoA\":[{\"TiCodProducto\":1041,\"TiCodCuenta\":6572500,\"TdSaldoD\":42.97}]}}}]

 

Using jsonpath.com with this output works, but in UCCX not, attach is the error that is appearing.

java.lang.Class.CastException: net.minidev.json.JSONArray cannot be cast to java.Number; nexted exception

 

Any idea?