How to convert Data Type of Values in Data Actions Responses?

We have some customer APIs to configure as DataActions in Genesys Cloud.
The limitation we are facing is the following:
We have a key value key_1 that can return information as an Integer, or as a String, depending on the data requested.

For Example:

"key_1": "NoSchedule"
"key_1": 0700

In the DataAction configuration, only one format is accepted per key, either String or Integer.
How can I convert the entire return to String in order to deal with this scenario?
Thank you.

So for my testing I have my endpoint return:

{
    "key_1": "NoSchedule",
    "key_2": 700
}

Note, in your example you had 0700 be returned. Data actions will fail on that since an integer should not have a leading zero, so I changed it from 0700 -> 700.

Here is a way to handle either numeric or string results:

{
  "translationMap": {"a" : "key_1", "b" : "key_2"},
  "translationMapDefaults": {},
  "successTemplate": "{\"a\" : \"$a.replace('\"', '')\", \"b\" : \"$b.replace('\"', '')\"}"
}

The idea here is that the $a and $b are surrounded by double quotes. This works for numeric variables, but will fail for strings since you would end up with two sets of double quotes. The $a.replace('"', '') is looking for any double quotes inside of the variable and removing them, which gets things working correctly for strings. As long as your string values will never have double quotes inside of them this should work out.

--Jason

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