Manvendra_Singh | 2021-09-29 08:04:21 UTC | #1
Hi team,
I have a small issue with translationMap logic I've build, getting some error for my condition. Although the condition mostly looks right, there's still something wrong that I'm not able to figure out. Let me share below my raw data, response map in data-action and the error I'm getting:
Raw Data { "systemToOrganizationMappings": { "ON_QUEUE": [ "e08eaf1b-ee47-4fa9-a231-1200e284798f" ], "AVAILABLE": [ "6a3af858-942f-489d-9700-5f9bcdcdae9b" ] }, "results": [ { "group": { "queueId": "0efd6dad-f308-495f-8b1f-b2e28a6629c0" }, "data": [ { "metric": "oUserPresences", "qualifier": "e08eaf1b-ee47-4fa9-a231-1200e284798f", "stats": { "count": 1 } }, { "metric": "oUserPresences", "qualifier": "6a3af858-942f-489d-9700-5f9bcdcdae9b", "stats": { "count": 1 } } ] } ] }
response map in data-action { "translationMap": { "Total": "$.results[0].data[0][?(@.qualifier == 'e08eaf1b-ee47-4fa9-a231-1200e284798f')].stats.count" }, "translationMapDefaults": { "Total": "0" }, "successTemplate": "{\"Total\": ${Total}}" }
Error while testing data-action
- Validate output against schema: JSON failed schema validation for the following reasons: Schema: # @/properties/Total. Error location: /Total. instance type (array) does not match any allowed primitive type (allowed: ["integer"])
Please help me in correcting this "translationMap" syntax.
Thanks in advance!
Jerome.Saint-Marc | 2021-09-29 12:11:30 UTC | #2
Hello,
A first comment: I think your JSONPath is incorrect. It should be "$.results[0].data[?(@.qualifier=='e08eaf1b-ee47-4fa9-a231-1200e284798f')].stats.count" You are looking for an element in the data array, with qualifier attribute set to 'e08eaf1b-ee47-4fa9-a231-1200e284798f'.
A JSONPath expression, like the one you are using (using a filter on an attribute), always returns an array. It can be an empty array, an array with one value, ...
You can use the successTemplateUtils.firstFromArray macro to retrieve the first element of this array. This macro can take a second parameter (optional) to define a default value when the array is empty. The JSONPath expression will return an empty array in some cases - e.g. if there is no metric with such qualifier value, ...
The translationMapDefaults will only be used/triggered if the response to your Platform API request does not contain some attribute names that you are using in your translationMap (e.g. results, data, ...). I have defined an empty array in the translationMapDefaults (totalArray), so that it will also use the default value (second parameter) from the successTemplateUtils.firstFromArray macro in this case.
Response configuration:
{ "translationMap": { "totalArray": "$.results[0].data[?(@.qualifier=='e08eaf1b-ee47-4fa9-a231-1200e284798f')].stats.count" }, "translationMapDefaults": { "totalArray": "[]" }, "successTemplate": "{\"Total\":${successTemplateUtils.firstFromArray(\"${totalArray}\",\"0\")}}" }
Regards,
Manvendra_Singh | 2021-09-29 13:56:32 UTC | #3
Awesome, thank you so much Jerome for such a quick response! We couldn't have figured this out by ourselves. I've tested, my data-action is working fine now with your configuration.
system | 2021-10-30 13:56:48 UTC | #4
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: 12170