GC Data action - response filter

Hello,
We have two types of queues: "front" queues for the inbound flows transfer and "back" queues for agents transfer. The "front" queue names ends with postfix "_front" and "back" queue names with postfix "_back", for example, "new_customers_front".

I need to receive all "front" queues that a given agent belongs to.

I can receive all queues that a given agent belongs to using GC API :

GET /api/v2/users/${input.AGENT_ID}/queues?joined=true

but I can't figure out how to define filter in the response translation map to receive "front" queues only. Is it possible to use regexp or java string functions in the translation map?
Or this task can be only implemented in Architect flow that calls the data action?

Thanks,
Irina

Hello,

Yes, it is possible to use regex in a JSONPath expression (within the Data Action).
The comparator to use is =~

I have defined an Output Contract containing an array of strings (frontQueues).

{
  "type": "object",
  "properties": {
    "frontQueues": {
      "type": "array",
      "items": {
        "title": "Item 1",
        "type": "string"
      }
    }
  },
  "additionalProperties": true
}

This is my Response Configuration.
The JSONPath expression will only match values ending with _front (case sensitive).

I noticed something which I didn't have time to investigate. If there are no queues with a name ending with _front, when I test my Data Action, it returns the following array: [ null ]
I haven't checked how that is then available in Architect - an array with a value (and the value IsNotSet) or an array with no value.

{
  "translationMap": {
    "myFrontQueues": "$.entities[?(@.name =~ /^.+_front/ )].name"
  },
  "translationMapDefaults": {
    "myFrontQueues": "[]"
  },
  "successTemplate": "{ \"frontQueues\": ${myFrontQueues} }"
}

Regards,

Thank you, Jerome!
The comparator =~ is exactly what I need. Is it a new feature? I haven't found any information about it in the Velocity macros for DA documentation.

One more question, can "front" be input parameter for DA in this expression:

"myFrontQueues": "$.entities[?(@.name =~ /^.+_front/ )].name" ?

So, the same data action could be used for finding all "front" or all "back" queues.

Thanks,
Irina

Hello,

The Data Action can leverage 2 things - a set of Velocity macros and JSONPath expressions (in the response configuration).
See Response configuration for data actions

JSONPath is what provides the way to parse the JSON response to select one or more attribute values (HTTP Body response).
You can see what's possible in terms of JSONPath operators here. I don't know if all of the functions in this page are supported (there are different versions of JSONPath with few variations - specifically on functions).

Unfortunately, it is not possible to leverage an input parameter (from the Input Contract) in a Response Configuration.
But you could possibly extract both with the same Data Action and decide in your Architect Flow if you are to use Front or Back Queues.

Output Contract:

{
  "type": "object",
  "properties": {
    "frontQueues": {
      "type": "array",
      "items": {
        "title": "Item 1",
        "type": "string"
      }
    },
    "backQueues": {
      "type": "array",
      "items": {
        "title": "Item 1",
        "type": "string"
      }
    }
  },
  "additionalProperties": true
}

Response Configuration:

{
  "translationMap": {
    "myFrontQueues": "$.entities[?(@.name =~ /^.+_front/ )].name",
    "myBackQueues": "$.entities[?(@.name =~ /^.+_back/ )].name"
  },
  "translationMapDefaults": {
    "myFrontQueues": "[]",
    "myBackQueues": "[]"
  },
  "successTemplate": "{ \"frontQueues\": ${myFrontQueues}, \"backQueues\": ${myBackQueues} }"
}

Regards,

Thank you for your help, Jerome!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.