VaunMcCarthy | 2020-08-28 03:05:11 UTC | #1
I'd like to get just the customer (item 0) from the array of the attributes here. What should the response/translation look like to do that please? This will give me an example to do this for others I have to do.Get-Payment-Outcome-20200828150251.custom.json|attachment (1.5 KB)
Jason_Mathison | 2020-08-28 14:50:38 UTC | #2
HI VaunMcCarthy,
Please provide an example of the response that you are trying to process.
--Jason
VaunMcCarthy | 2020-08-28 20:12:22 UTC | #3
Hi Jason:
{ "id": "3206faae-32ff-48f1-beab-a2365385b262", "startTime": "2020-08-27T22:21:19.874Z", "endTime": "2020-08-27T22:23:04.972Z", "address": "tel:+64XXXXXXXX", "participants": [ { "id": "2bb5d7b5-8069-4ff1-82dd-65aa6cf6208f", "startTime": "2020-08-27T22:21:19.874Z", "endTime": "2020-08-27T22:23:04.298Z", "connectedTime": "2020-08-27T22:21:20.055Z", "name": "Mobile Number, New Zealand", "purpose": "external", "participantType": "External", "address": "tel:+64XXXXXXXX", "ani": "tel:+64XXXXXXXX", "aniName": "Mobile Number, New Zealand", "dnis": "tel:+64XXXXXXXX", "wrapupRequired": false, "attributes": { "InArrears": "false", "cardAmount": "100.01", "accountCLISearch": "success", "balanceDollars": "0", "pinSearch": "successcorrect", "overrideOpen": "false", "resellerAccount": "false", "manualEmergency": "false", "pinEntered": "XXXX", "accountNumber": "XXXXXX", "multipleEquipment": "false", "accountSearch": "success", "overrideClosed": "false", "accountStatus": "Active", "callSource": "IVR", "accountSearchType": "CLI", "serviceStatus": "open", "accountBalanceDecimal": "0", "balanceCents": "0", "accountBalance": "0.00|", "agentCount": "38", **"paymentOutcome": "XXXXXXXApproved"** },...
I want to obtain certain participant data/attributes but ONLY from the customer/external participant. For example, I want to get that paymentOutcome attribute so I can then display it into an agent script. Without a first from array function, I end up with a collection of this attribute from ALL participants, where all the others are NULL.
Since the data actions I've looked at can't filter for this info based on participant, I've assumed I need to just get the first instance of the attribute I"m looking for that has an actual value set. But also allowing for a default where the attribute may not exist.
Thanks
Jason_Mathison | 2020-08-31 21:18:21 UTC | #4
So you can filter out your JSONPath with an expression like $.participants[?(@.purpose == 'external')].attributes.paymentOutcome
to only return the value of an external participant.
For working through JSON Path I typically use the following site, as it behaves the same way as our Data Actions: http://jsonpath.herokuapp.com/
--Jason
VaunMcCarthy | 2020-08-31 22:21:54 UTC | #5
Jason_Mathison, post:4, topic:8683
$.participants[?(@.purpose == 'external')].attributes.paymentOutcome
Thanks Jason
Would that expression go in the successTemplate section of the Response? So...
"successTemplate": "$.participants[?(@.purpose == 'external')].attributes.paymentOutcome"
VaunMcCarthy | 2020-08-31 23:19:37 UTC | #6
attached the action I'm trying to get to work here. Just having a problem getting the response into the contract item.Get-Payment-Outcome-Copy-20200901111818.custom.json|attachment (1.6 KB)
anon28885283 | 2020-09-01 03:08:54 UTC | #7
Your successTemplate needs to match the output contract. So in your case you should modify the output contract to just have a string property "paymentOutcome" instead of the nested array/objects you currently have.
VaunMcCarthy | 2020-09-01 07:35:29 UTC | #8
Not sure I follow you. I'd need the top layer object anyway, eg Conversation, then are you saying I just have a single string property under that?
Jason_Mathison | 2020-09-01 11:32:53 UTC | #9
Correct, all you need is a top level object (which doesn't have to be named) with a "paymentOutcome" string inside of it.
VaunMcCarthy | 2020-09-01 19:58:00 UTC | #10
Okay, have followed that and have this as the contract:
{ "type": "object", "properties": { "paymentOutcome": { "type": "string" } }, "additionalProperties": true }
and this as the Response:
{ "translationMap": { "Filter1": "$.participants[?(@.purpose == 'external')].attributes.paymentOutcome" }, "translationMapDefaults": {}, "successTemplate": "{\r\n \"paymentOutcome\": ${Filter1}\r\n}" }
But it throws an error that it's getting that array level back but expecting a string based on the contract
Jason_Mathison | 2020-09-01 20:05:05 UTC | #11
It looks like you last posting may have been messed up by the forum. Ideally could you export and post your action? If not, if you highlight your configuration and hit the </> button it should stop hiding characters.
--Jason
Jason_Mathison | 2020-09-01 20:26:05 UTC | #12
Ah, the JSONPath is returning an array since there could be more than one result. This is what the firstFromArray utility is for:
{ "translationMap": { "Filter1": ".participants[?(@.purpose == 'external')].attributes.paymentOutcome" }, "translationMapDefaults": {}, "successTemplate": "{\r\n \"paymentOutcome\": ${successTemplateUtils.firstFromArray(\"${Filter1}\")}\r\n}" }
VaunMcCarthy | 2020-09-01 21:02:53 UTC | #13
Jason_Mathison, post:12, topic:8683
{ "translationMap": { "Filter1": ".participants[?(@.purpose == 'external')].attributes.paymentOutcome" }, "translationMapDefaults": {}, "successTemplate": "{\r\n \"paymentOutcome\": ${successTemplateUtils.firstFromArray(\"${Filter1}\")}\r\n}" }
Thanks Jason, yes that has fixed it. When does that purpose value change and how is it determined? In some calls that shows as external, and others as customer.
VaunMcCarthy | 2020-09-02 03:01:08 UTC | #14
how should I modify the translationMapDefaults and successTemplate to take into account a possible no response if that attribute doesn't exist? I've tried a few things myself neither seem to work, I'd just have thought
{ "translationMap": { "Filter1": ".participants[?(@.purpose == 'external')].attributes.paymentOutcome" }, "translationMapDefaults": {}, "successTemplate": "{\r\n "paymentOutcome": {successTemplateUtils.firstFromArray(\"{Filter1}")}\r\n},\"NO VALUE\"" }
or similar?
Jason_Mathison | 2020-09-02 10:36:22 UTC | #15
External vs. customer: https://developer.mypurecloud.com/forum/t/difference-between-external-and-customer/4360 I don't know much about analytics, if you need additional information I would post your question to one of the Analytics forums.
You could search for both customer and external like this: .participants[?(@.purpose == 'external' || @.purpose == 'customer')].attributes.paymentOutcome
There are a couple of ways to handle the attribute not existing. One way would be to ignore it and have the data action fail. This is a reasonable approach if the response is effectively useless to you without this value being set.
The default value for the firstFromArray like you have is perfectly reasonable if the response is still useful to you, or you want to be able to identify the "The data action worked, but didn't have a paymentOutcome" scenario.
--Jason
Jason_Mathison | 2020-09-02 10:39:00 UTC | #16
I didn't read you latest response very well, what was going wrong when you tried to use a default value with firstFromArray?
VaunMcCarthy | 2020-09-02 20:38:14 UTC | #17
Hi Jason
To clarify, here's my response JSON:
{ "translationMap": { "Filter1": ".participants[?(@.purpose == 'external')].attributes.paymentOutcome" }, "translationMapDefaults": {}, "successTemplate": "{\r\n \"paymentOutcome\": ${successTemplateUtils.firstFromArray(\"${Filter1}\")}\r\n}" }
When I search for a conversation where there is no paymentOutcome attribute I get this:
9. Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unexpected character ('}' (code 125)): expected a value at [Source: (String)"{ "paymentOutcome": }"; line: 3, column: 2]' Template:'{ "paymentOutcome": ${successTemplateUtils.firstFromArray("${Filter1}")} }'.
So I've tried adding a default in the successtemplate:
{ "translationMap": { "Filter1": ".participants[?(@.purpose == 'external')].attributes.paymentOutcome" }, "translationMapDefaults": {}, "successTemplate": "{\r\n \"paymentOutcome\": ${successTemplateUtils.firstFromArray(\"${Filter1}\",\"NO VALUE\")}\" }" }
and I get:
10. Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unrecognized token 'NO': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (String)"{ "paymentOutcome": NO VALUE" }"; line: 2, column: 24]' Template:'{ "paymentOutcome": ${successTemplateUtils.firstFromArray("${Filter1}","NO VALUE")}" }'.
Jason_Mathison | 2020-09-02 20:46:28 UTC | #18
Can you either user the </> on your configuration or post an export of your action? Some of the quote escaping looks wrong, but the forum markup processing can cause that.
VaunMcCarthy | 2020-09-02 20:47:07 UTC | #19
Get-Payment-Outcome-from-Conversation-ID-Copy-2020090384645.custom.json|attachment (1.2 KB)
VaunMcCarthy | 2020-09-02 21:06:02 UTC | #20
Not sure if I mentioned, but I"m looking to only use this Data Action in an agent script, which is why I'm trying to get the default thing to work rather than just let it fail and handle that in Architect.
Jason_Mathison | 2020-09-02 21:07:07 UTC | #21
Sigh, you have entered the horror of quoting escapes. Give this a try, changing the value of default to whatever you want.
` "successTemplate": "#set($default = \"No-Data\") {\r\n \"paymentOutcome\": ${successTemplateUtils.firstFromArray(\"${Filter1}\", \"$esc.quote$default$esc.quote\")}\r\n}"`
VaunMcCarthy | 2020-09-03 02:27:26 UTC | #22
Horror indeed. Thanks Jason, that's definitely resolved it. Just when I thought I was slightly on the right track there's yet another depth to this JSON rabbit hole :slight_smile:
Thanks again.
VaunMcCarthy | 2020-09-03 06:17:33 UTC | #23
If I wanted to add an additional attribute to this, would I just create a new Filter2 using the second attribute name?
For the success template, is it just enough to append what's there currently to put in the , \r\n "otherAttribute": then copy what's in there but pointing at Filter2?
Jason_Mathison | 2020-09-03 11:43:03 UTC | #24
That should work.
system | 2020-10-04 11:51:08 UTC | #25
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 8683