cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
12899
Views
38
Helpful
32
Replies

JSON Response from REST Client CVP 11.5

dmehta
Level 1
Level 1

Hi Team,

I am trying to make a REST call using Call studio REST Client to an endpoint.  However, in my json response, i get multiple values.

Although, i could see all the responses in the log, my requirement is to utilize only 1 response.

As per documentation, it looks like i can achieve the same outcome using  json expression but it doesnt work.

Example  my response id looks like this:

{

  "item": {

   "id": 123,

   "url": "https://{subdomain}.zendesk.com/api/v2/items/123.json",

   "name": "Wibble",

   ...

   "created_at": "2012-04-04T09:14:57Z"

  }

}

Now, i just need to store value of id in one of the session data. However, current response_body stores the entire response.

My xpath/json path looks like this :  /item/id


Please help.


32 Replies 32

If you use $.response as your JSONPath expression in the Rest Client

element, VXML Server will parse it into element data for you.

When you choose POST as your HTTP method the element changes and removes the XPath/JSONPath Expression option

I tried to use the Set Value element with this POST request but we get an error:

10.54.147.65.1524228916352.2.test,04/20/2018 08:55:16.853, The error was: A built-in element encountered an exception of type com.audium.server.AudiumException. Java Script Execution error The root cause was: javax.script.ScriptException: sun.org.mozilla.javascript.internal.WrappedException: Wrapped com.jayway.jsonpath.PathNotFoundException: Path token: '[0]' not found. (<Unknown source>#4) in <Unknown source> at line number 4

with this setting:

importPackage(com.audium.server.cvpUtil);

var val={Data.Element.do_ANI_Lookup.response_body};

var path="$[0].aboNum";

JSONPathUtil.eval(val,path);

If this is the JSON you're getting back, then you should use "$.response.aboNum"

{

    "response": {

        "salesPlanAff": "100",

        "statusCd": "Active",

        "accountSubTypeCd": "BusinessOwner",

        "aboNum": "2303",

        "awardCd": "FEM",

        "awardDesc": "Founders Emerald"

    }

}

Yes that worked !! thanks. I was thinking [0] was referring to the first part of the JSON response_body,  "response" but we needed to be specific then I guess.

I don't know why Cisco didn't allow for the $.response XPATH/JSONPATH field with a POST vs GET.

Janine,

The json returned by the customer WebService has changed and I was wonder if you could give me a tip on how to parse it in the SET Value element now that its in an array.

10.54.148.161.1524690965641.0. WS,04/25/2018 17:16:06.376,doANI_Lookup,exit,done

10.54.148.161.1524690965641.0. WS,04/25/2018 17:16:06.376,parseResponse,enter,

10.54.148.161.1524690965641.0. WS,04/25/2018 17:16:06.579,parseResponse,custom,aboNum,sun.org.mozilla.javascript.internal.WrappedException: Wrapped com.jayway.jsonpath.PathNotFoundException: Path 'aboNum' is being applied to an array. Arrays can not have attributes. ( at line number 4

{

"response": [

{

"salesPlanAff": "100",

"cntryCd": "MY",

"languageCd": "en",

"statusCd": "Active",

"accountSubTypeCd": "BusinessOwner",

"aboNum": "2303",

"awardCd": "375",

"awardDesc": "Founders Emerald"

}

],

"numOfRecords": "1",

"responseCode": "200",

"responseMessage": "OK"

}

I think I got it figured out myself

var path="$response.[0].aboNum";

JSONPathUtil.eval(val,path);

Good job. I would have done it slightly differently

"$.response[0].aboNum"   but if yours works, great. Maybe a dot here or

there doesn't quite matter. You can test it using jsonpath.com - just

paste your json in the  left bottom box, and enter your path expression

above it - the result displays on the right side.

Hello Janine,

 

I am having problem on a step before, on Rest_Client node. I can compose a Endpoint URL with address: https://host-address/api/contactcenter/{Data.Element.getRUT.value}? Where getRUT is a element where I ask the RUT (8 number digits) information for the customer.

 

Also is necessary the other fields as: Parameters / Headers / JSONPath. I filled only the Headers field with: Content-Type : application/json

 

I'll need retrieve all var-datas from this rest as bellow:

 

{"rut":"99999999","name":"THE CUSTOMER","ccos":"2","last_sale":"26748550","last_sale_date":"2019-06-10","sale_type":"S\/I","seller_code":"195","collector_code":"S\/I"}

Wether is needed, what would be the JSONPath?

 

 

Rest_Client.jpg

 

Thank you so much!

 

Cláudio Costa

Claudio,

 

You can leave that field blank.

Use the Set Value element to parse the REST response.

 

Example here:

http://orourke.tv/web/doku.php?id=vendors:cisco:uc:cvp:rest&s[]=json

 

Gerry

Hi Gerry,

 

Thank you so much! I've found the main reason my rest_client didn't work before, 

Caused by: com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: host.domain.cl

 

Then, after fixed this conectivid issue, everything is working as well. Any tips to how parse these variables from CVP to ICM script? I'll need use some of them to define the routing direction (based on seller_code variable, I'll need to try send the call for specific agent) as well as show all fields in finesse interface for the agents.

 

Thank you so much.

 

Cláudio Costa

Cladio,

Can you post your JSON response and what information you need to send back to ICM?

Claudio,

Here's an example of one of my scripts and how I parse the JSON information.

JSON response from my server:

 

{
"OUTLAST_PAYMENT":"200.00"
"OUTLAST_PAYMENT_DATE":"06/13/2019"
"OUTRETURN_CODE":"00"
"OUTRETURN_MESSAGE":"Account payment info. passed !"
}

 

Here's how I extract the information. I don't know if this is the right or best way to do this but this is how I successful extract the information. I have a Set Value element from the Math category. Under the Setting tab, I have 5 local variables defined (a separate variable for each piece of information I need to extract from the JSON response):

 

Name: localOUTLAST_PAYMENT, value:

importPackage(com.audium.server.cvpUtil)

var json = {Data.Element.rest_Get_Payment_Info.response_body}
var path = "$.OUTLAST_PAYMENT"

JSONPathUtil.eval(json,path)

 

Name: localOUTLAST_PAYMENT_DATE, value:

var json = {Data.Element.rest_Get_Payment_Info.response_body}
var path = "$.OUTLAST_PAYMENT_DATE"

JSONPathUtil.eval(json,path)

 

Name: localOUTRETURN_CODE, value: 

var json = {Data.Element.rest_Get_Payment_Info.response_body}
var path = "$.OUTRETURN_MESSAGE"

JSONPathUtil.eval(json,path)

 

Name: localOUTRETURN_MESSAGE, value:

var json = {Data.Element.rest_Get_Payment_Info.response_body}
var path = "$.OUTRETURN_CODE"

JSONPathUtil.eval(json,path)

 

Name:localOUTLAST_PAYMENT_RETURNED (not in every response), value:

var json = {Data.Element.rest_Get_Payment_Info.response_body}
var path = "$.OUTLAST_PAYMENT_RETURNED"

JSONPathUtil.eval(json,path)

 

In the Data tab of the element, Session Data pane:

lastPaymentAmount, session data: {LocalVar.local_OUTLAST_PAYMENT}, create: After (VERY important to do this after, not before. If you do before, your variable will be empty)

Do this for each piece of data you want to return to ICM.

 

See attached file for screenshots of what is returned in the Set Value element.

Once you have the local variable data stored in your session variables, you can return those to ICM in the Caller Input, External VXML 0, 1, 2, and 3 variables in the CVP Subdialog Return element. If you have more than 5 pieces of data you need to return to ICM, you can either use a ReqICMLabel element or concatenate your data into CSV, return it to ICM then extract it using Before and After statements in a Set Variable node. If you need to do this, let me know and I'll show you an example of how I had to do this in the past.

I hope this helps.

 

 

Hi Everyone,

 

is it possible to use JSONPath filters on the JSON response?

 

I am trying to retrieve a specific value from multiple responses.

 

{"code":"00","message":"Account Enquiry Successful","reference":null,"accounts":[{"code":null,"message":null,"reference":null,"customerNumber":"0987654321","accountNumber":"0123456789","accountName":"Paul  Onwude"},{"code":null,"message":null,"reference":null,"customerNumber":"9087654321","accountNumber":"1234567890","accountName":"Peter  Onwude"}]}

 

I want  to get the account name where account  number is 1234567890.

 

$.accounts[?(@.accountNumber=='1234567890')].accountName

 

When  i apply the filter  in CVP Call studio, i  get syntax error (<Unknown Source).

 

Same query on https://jsonpath.com/ returns the desired result.

 

Is there any other way to  achieve this?

 

Regards

 

Paul