Rishi_Sachdeva | 2022-03-02 20:42:56 UTC | #1
We need a data action that can calculate the total number of connected calls for the current interval. I created a custom data action as follows: Input Contract: { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Check for interactions with DNIS", "description": "Check if we had interactions for a certain DNIS", "type": "object", "required": "DNIS", "Date" ], "properties": { "DNIS": { "description": "DNIS in e.164 format", "type": "string" }, "Date": { "description": "Date in the format YYYY-MM-DDThh:mm:ss/YYYY-MM-DDThh:mm:ss (yesterday/today+1 for example, a query that does not exceed 31 days)", "type": "string", "format": "YYYY-MM-DDThh:mm:ss/YYYY-MM-DDThh:mm:ss" } }, "additionalProperties": true } Output Contract: { "title": "Check for interactions with DNIS", "description": "Returns the total number of connected conversations", "type": "object", "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "total": { "description": "The Total number of connected calls that contain the DNIS you looked up", "type": "array", "items":{ "type":"integer" } } }, "additionalProperties": true } Request Configuration { "requestUrlTemplate": "/api/v2/analytics/conversations/details/query", "requestType": "POST", "headers": { "Content-Type": "application/json" }, "requestTemplate": "{\n \"interval\": \"${input.Date}\",\n \"order\": \"asc\",\n \"orderBy\": \"conversationStart\",\n \"paging\": {\n \"pageSize\": 25,\n \"pageNumber\": 1\n },\n \"segmentFilters\": [\n {\n \"type\": \"and\",\n \"predicates\": [\n {\n \"type\": \"dimension\",\n \"dimension\": \"dnis\",\n \"operator\": \"matches\",\n \"value\": \"${input.DNIS}\"\n }\n ]\n }\n ],\n\"conversationFilters\": [\n {\n \"type\": \"or\",\n \"predicates\": [\n {\n \"type\": \"metric\",\n \"metric\": \"nConnected\",\n \"range\": {\n \"gt\": 0\n }\n }\n ]\n }\n ]\n}" } Response config: { "translationMap": { "total": "$.totalHits" }, "translationMapDefaults": {}, "successTemplate": "{\"totalHits\": ${total}}" } The Action successfully run but with no number for totalHits. ![image|690x241
Can I get some help fixing this Data Action?
Jason_Mathison | 2022-03-02 20:55:58 UTC | #2
I recommend that you take the output of the execution step and put it into http://jsonpath.herokuapp.com/ to work out what your translationmap JSONPath should be.
Rishi_Sachdeva | 2022-03-02 21:13:47 UTC | #3
Hi Jason, thank you for the reply. I am not familiar with this tool but after using the output from the execute step , I am getting this output from that link
Jason_Mathison | 2022-03-02 21:44:30 UTC | #4
You need to put something in the "Path" box under the JSON you are trying to filter.
I recommend working your way down to the stuff you want, so using the example on their page you could do each line to progressively filter. $ $.store $.store.book
Jerome.Saint-Marc | 2022-03-03 07:05:29 UTC | #5
Hello,
You have 2 errors in your Data Action configuration.
The first problem is in your Output Contract. "total" should be an integer - it should not be an array of integers (as you have configured it in your Data Action).
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "Check for interactions with DNIS", "description": "Returns the total number of connected conversations", "type": "object", "properties": { "total": { "description": "The Total number of connected calls that contain the DNIS you looked up", "type": "integer" } }, "additionalProperties": true }
The second problem is in your Response Configuration. In your successTemplate, you are using "totalHits" as attribute/property name - but you declared "total" in your Output Contract. The names must match if you want to extract the associated value properly.
{ "translationMap": { "totalConnected": "$.totalHits" }, "translationMapDefaults": { "totalConnected": "0" }, "successTemplate": "{\"total\": ${totalConnected}}" }
Regards,
Rishi_Sachdeva | 2022-03-03 19:00:32 UTC | #6
Thanks a lot @Jerome.Saint-Marc that worked for me. Appreciate your quick response and the help provided.
system | 2022-04-03 19:00:34 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: 13770