Genesys Cloud - Main

 View Only

Sign Up

  Thread closed by the administrator, not accepting new replies.
  • 1.  Web Service Data Actions - Analytics Query Builder

    Posted 09-26-2018 19:09
    No replies, thread closed.
    Hello,

    I would like to know if it is possible to transform a Queue Observation Query (created with Developer Tools) into an Integration Action (Web Services Data Actions).

    I have a json request body, and response body, but I can't seem to map them into the required Input/output contracts and request/response configurations.

    I would like to use a Web Service Data Action to be able to get the waiting callers in a Queue, for displaying in a script.

    Generated Query:

    { "filter": { "type": "and", "predicates": [ { "type": "dimension", "dimension": "queueId", "operator": "matches", "value": "97e24b6b-1692-4aef-81db-573aa90de81a" }, { "type": "dimension", "dimension": "mediaType", "operator": "matches", "value": "voice" } ] }, "metrics": [ "oWaiting" ] }

    Query Result:

    { "results": [ { "group": { "mediaType": "voice", "queueId": "97e24b6b-1692-4aef-81db-573aa90de81a" }, "data": [ { "metric": "oWaiting", "stats": { "count": 0 } } ] } ] }

    Thx in advance

    ------------------------------
    Steven Deferme
    Quant ICT
    ------------------------------


  • 2.  RE: Web Service Data Actions - Analytics Query Builder

    Posted 09-27-2018 04:58
    No replies, thread closed.
    I managed to get a raw response, but the translation fails.

    I get response:
    {
    "results": [
    {
    "group": {
    "mediaType": "voice",
    "queueId": "637a6cb2-ad14-4213-a354-988015a21e7a"
    },
    "data": [
    {
    "metric": "oWaiting",
    "stats": {
    "count": 0
    }
    }
    ]
    }
    ]
    }

    But the translation fails:
    {
    "status": 400,
    "code": "bad.request",
    "message": "Failed while processing the translation map. Could not resolve value for the key: 'count' and no default value was configured. Additional details: No results for path: $['count']",
    "messageParams": {},
    "contextId": "4c195cd6-2b05-4ca7-af1d-f332bc15db3e",
    "details": [],
    "errors": []
    }

    I use this response configuration:
    {
    "translationMap": {
    "count": "$.count",
    "mediaType": "$.mediaType",
    "queueId": "$.queueId"
    },
    "translationMapDefaults": {},
    "successTemplate": "{\"results\": [{\"group\": {\"mediaType\": ${mediaType},\"queueId\": ${queueId}},\"data\": [{\"metric\": \"oWaiting\",\"stats\": {\"count\": ${count}}}]}]}"
    }


    ------------------------------
    Steven Deferme
    Quant ICT
    ------------------------------



  • 3.  RE: Web Service Data Actions - Analytics Query Builder
    Best Answer

    Posted 09-27-2018 09:28
    No replies, thread closed.
    Hello,

    I've managed to get it working. I'll post my config, in case someone has the same question:

    Scenario: provide the number of calls waiting in a certain queue:

    Input Contract

    queueId= the id of the queue
    mediaType= the type of media (callback, chat, cobrowse, email, screenshare, voice)
    metric= oWaiting
    {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
    "queueId": {
    "type": "string"
    },
    "mediaType": {
    "type": "string"
    },
    "metric": {
    "type": "string"
    }
    }
    }

    Output Contract

    queueId = returned same as request
    mediatype= returned same as request
    metric = returned same as request
    count = number of calls waiting in the queue.
    {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
    "queueId": {
    "type": "string"
    },
    "mediaType": {
    "type": "string"
    },
    "count": {
    "type": "number"
    },
    "metric": {
    "type": "string"
    }
    }
    }

    Request Configuration

    {
    "requestUrlTemplate": "https://api.mypurecloud.ie/api/v2/analytics/queues/observations/query",
    "requestType": "POST",
    "headers": {
    "Transfer-Encoding": "buffered",
    "Authorization": "bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "content-type": "application/json"
    },
    "requestTemplate": "{\"filter\":{\"type\": \"and\", \"clauses\": [{ \"type\": \"and\", \"predicates\": [{ \"type\": \"dimension\", \"dimension\": \"queueId\", \"operator\": \"matches\", \"value\": \"${input.queueID}\"}]}], \"predicates\": [{ \"type\": \"dimension\", \"dimension\": \"mediaType\", \"operator\": \"matches\", \"value\": \"${input.mediaType}\"}]}, \"metrics\":[ \"${input.metric}\"]}"
    }

    Response Configuration

    {
    "translationMap": {
    "count": "$.results[0].data[0].stats.count",
    "queueId": "$.results[0].group.queueId",
    "mediaType": "$.results[0].group.mediaType",
    "metric": "$.results[0].data[0].metric"
    },
    "translationMapDefaults": {},
    "successTemplate": "{\"mediaType\": ${mediaType},\"queueId\": ${queueId},\"metric\": ${metric},\"count\": ${count}}"
    }


    ------------------------------
    Steven Deferme
    Quant ICT
    ------------------------------



  • 4.  RE: Web Service Data Actions - Analytics Query Builder

    Posted 09-27-2018 09:32
    No replies, thread closed.
    The problem is your configuration.  

    $.count looks for a node labeled "count" at the root of your response.  What you're really looking for is $.results.data.count.  More than that, you're going to want to apply a filter to find the "type" of count that you're looking for (see below for an example).  It's worth reviewing jsonpath notation to see what's really available to you in terms of pathing/filtering (https://github.com/json-path/JsonPath).  There's also a great tool out there that allows you to test out your JSON path (http://jsonpath.herokuapp.com/ you can paste in your own JSON then apply your filters to see what comes back).  Lastly, it's worth reviewing the default values portion of the config so you can set a default response in case there are no results from the analytics API (the analytics API doesn't return a value if there are no results, which can cause the same sort of failure you're seeing now).

    Try using this config:
    {
    "translationMap": {
    "count": "$..data.[?(@.metric=='oWaiting')].stats.count",
    "mediaType": "$.mediaType",
    "queueId": "$.queueId"
    },
    "translationMapDefaults": {},
    "successTemplate": "{\"results\": [{\"group\": {\"mediaType\": ${mediaType},\"queueId\": ${queueId}},\"data\": [{\"metric\": \"oWaiting\",\"stats\": {\"count\": ${count}}}]}]}"
    }

    ------------------------------
    Richard Schott
    Genesys - Employees
    ------------------------------



  • 5.  RE: Web Service Data Actions - Analytics Query Builder

    Posted 09-27-2018 09:47
    Edited by R. J. Smith 09-27-2018 09:49
    No replies, thread closed.
    EDIT: Apologies, I wasn't responding to last msg - glad you got it working!

    Instead of this:

    "translationMap": {
    "count": "$.count",
    "mediaType": "$.mediaType",
    "queueId": "$.queueId"
    }

    Try this for your translationMap:

    "translationMap": {
    "count": "$..count",
    "mediaType": "$..mediaType",
    "queueId": "$..queueId"
    }

    The '..' operator is for recursive descent (ie, 'go find it wherever it is'):
    http://goessner.net/articles/JsonPath/index.html

    ------------------------------
    R. J. Smith
    Genesys - Employees
    ------------------------------



  • 6.  RE: Web Service Data Actions - Analytics Query Builder

    Posted 09-27-2018 15:14
    No replies, thread closed.

    Hello,

    It works with the recursive descent.

    Thanks you for your answer

    Steven



    ------------------------------
    Steven Deferme
    Quant ICT
    ------------------------------



  • 7.  RE: Web Service Data Actions - Analytics Query Builder

    Posted 09-28-2018 08:23
    No replies, thread closed.
    One thing to keep in mind is that doing a deep scan or finding results by array position "could" have some issues if the api you're hitting has the potential to return multiple results within that array or with that label.  I think you're going to be fine with the particular action you're using, but other analytics queries definitely have varied responses based on observations.  In those cases, using a filtering statement that matches based on other attributes within the array can be very useful.

    ------------------------------
    Richard Schott
    Genesys - Employees
    ------------------------------