NielsS | 2018-05-08 14:19:14 UTC | #1
I tried to get the amount of people waiting in a queue with a PureCloud Data Action.
The resultset is a all data and I want to get calls waiting instead of all.
Who can help me?
The action Setup which does not work:
Contracts: Input: { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Estimated Wait Time Request", "description": "The number of waiting in a queue.", "type": "object", "required": [ "QUEUEID" ], "properties": { "QUEUEID": { "description": "The queue ID.", "type": "string" } } }
Output: { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Get waiting", "description": "Returns the number of waiting.", "type": "object", "properties": { "results.data.metric.oWaiting": { "description": "Result", "type": "string", "title": "results.data.metric" } } }
Configuration: Request: { "requestUrlTemplate": "/api/v2/analytics/queues/observations/query", "requestType": "POST", "headers": { "UserAgent": "PureCloudIntegrations/1.0" }, "requestTemplate": "{\"filter\": {\"type\":\"or\",\"predicates\": [{\"dimension\": \"queueId\",\"value\": \"${input.QUEUE_ID}\"}]}}" }
Response: { "translationMap": {}, "successTemplate": "${rawResult}" }
Jason_Mathison | 2018-05-08 14:59:16 UTC | #2
A quick note first, it is a lot easier to try out your action if you export it to a .json file and attach the file to the thread :slight_smile:
Could you post exactly what you are getting back that is problematic? I am looking at this now, but analytics isn't really my specialty so it could take me a bit.
Jason_Mathison | 2018-05-08 15:38:31 UTC | #3
Without seeing your exact output you are getting back from analytics I am pretty limited, but based on an example I got from a coworker (Thanks @tim.smith) I think creating a variable in your translation map with this JSONPath might work:
$.results[?(@.group.mediaType=="voice")].data[?(@.metric=="oWaiting")].stats.count
You probably need to escape the quotes, but it should get you in the right direction.
FYI, what I did was put in the output from analytics into http://jsonpath.com/? and work my way through creating the JSONPath.
anon28066628 | 2018-05-08 18:21:14 UTC | #4
Love those JSONpath filters :). Side note, the filters put the filtered values in an array, even if there's only one, so to simplify things, you might use this macro in your response template:
"myFilteredField": ${successTemplateUtils.firstFromArray(${myFilteredField})}
https://help.mypurecloud.com/articles/velocity-macros-data-actions/#firstFromArray
Jason_Mathison | 2018-05-08 18:25:39 UTC | #5
The attached action worked correctly in my test environment. Along with the JSONPath that I posted above I had to deal with JSONPath returning an array by getting the first entry with ${successTemplateUtils.firstFromArray(\"${WaitingInQueue}\")}}" (What RJ said right before I got this out!)
<a class="attachment" href="/forum/uploads/db6296/original/1X/35efadb4fcc004f1bddd586f5a6fb26262ae747b.json">AnalyticsTest-20180508135457.custom.json</a> (1.7 KB)
NielsS | 2018-05-09 09:01:04 UTC | #6
These answers made a lot more clear!
Also found the import/export buttons (did not see it earlier). Thanks for the tips and explanations how the output is achieved.
system | 2018-06-09 09:01:06 UTC | #7
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: 2831