Legacy Dev Forum Posts

 View Only

Sign Up

Replace Null values in response API

  • 1.  Replace Null values in response API

    Posted 06-05-2025 18:42

    Jeremy_MONZO | 2020-11-24 09:12:18 UTC | #1

    Hello,

    In a Data Action, I would like replace the null value by a default value (0) in the output response. I have tried to achieve this result with translationMapDefault with no success. My goal is instead makes control in Architect for check if the variable is null or not use the data action to make this action.

    Get-Nb-Agents-in-IDLE-Status-20201124100927.custom.json|attachment (1.4 KB)

    REQUEST { "requestUrlTemplate": "/api/v2/analytics/queues/observations/query", "requestType": "POST", "headers": {}, "requestTemplate": "{ \"filter\": { \"type\": \"and\", \"clauses\": [{\"type\": \"and\", \"predicates\": [ { \"dimension\": \"queueID\", \"value\": \"${input.QueueID}\" } ] } ], \"predicates\": [{ \"dimension\": \"mediaType\", \"value\": \"voice\" } ] }, \"metrics\": [\"oOnQueueUsers\"], \"detailMetrics\": []}" }

    RESPONSE { "translationMap": { "iIDLE": "$.results[*].data[?(@.qualifier==\"IDLE\")].stats.count" }, "translationMapDefaults": { }, "successTemplate": "{\"iIDLE\" : ${iIDLE}}" }

    thansk for your hints jeremy


    Jerome.Saint-Marc | 2020-11-24 10:11:37 UTC | #2

    Hello,

    A first comment regarding your Queue Observation query. If you are only interested in the oOnQueueUsers metric, it is not necessary to filter by mediaType. The oOnQueueUsers metric does not take into account the mediaType - only the queueID. You could use something like this directly:

    { "filter": { "type": "and", "predicates": [ { "type": "dimension", "dimension": "queueId", "operator": "matches", "value": "${input.QueueID}" } ] }, "metrics": [ "oOnQueueUsers" ] }

    If you plan to request this single metric (oOnQueueUsers) for a single queue, then I assume you might be more interested in getting an integer variable as an output of your Data Action (0 if no idle users) instead of an array.

    So in my Output Contract, I have defined iIDLE as a type: "integer" (instead of an "array" of integers).

    And I have used the following for my Configuration Response:

    { "translationMap": { "idleagentsarray": "$.results[0].data[?(@.qualifier == 'IDLE')].stats.count" }, "translationMapDefaults": { "idleagentsarray": "[]" }, "successTemplate": "{\"iIDLE\": ${successTemplateUtils.firstFromArray(\"${idleagentsarray}\",\"0\")} }" }

    idleagentsarray will be:

    • an array with a single value (as we filter on a single queueID here) if there are some idle agents. The JSONPath expression from translationMap.idleagentsarray bringing back a result with success (array).
    • an empty array (value coming from translationMapDefaults.idleagentsarray) if there are no idle agents. The translationMap.idleagentsarray JSONPath expression fails/returns null - translationMapDefaults is used in this case.

    In the successTemplate, we use the successTemplateUtils.firstFromArray macro. It will extract first value from the idleagentsarray (if the array is not empty). Or it will return 0 if the idleagentsarray is empty (second parameter of the successTemplateUtils.firstFromArray macro).

    Regards,


    Jeremy_MONZO | 2020-11-24 15:45:22 UTC | #3

    Hello Jerome,

    thanks for your hints and detailed explanation. I have tested and it works now like expected.

    Jeremy


    system | 2020-12-25 15:45:23 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: 9372