Legacy Dev Forum Posts

 View Only

Sign Up

Data action - resolving translation maps

  • 1.  Data action - resolving translation maps

    Posted 06-05-2025 18:43

    garimabalodi | 2022-11-15 09:40:04 UTC | #1

    Hi Dev Forum,

    I am trying to create a data action that would fetch me result of fromUser where method="ACK" from the below API response(pasted in the end ).

    I am using translation map as below:- "translationMap": { "fromUser": "$.data[?(@.method == 'ACK')].fromUser" }

    it gives me an error on invalid schema when I test my data action. what could be the issue?

    "message": "JSON failed schema validation for the following reasons: Schema: # @/properties/fromUser. Error location: /fromUser. instance type (array) does not match any allowed primitive type (allowed: ["string"])", "code": "invalid. schema"

    response of the platform API is:- { "data": { "id": "0", "method": " ACK ", "ruriUser": "00912269228600", "ruriDomain": "10.107.217.91", " fromUser ": "07003552060", "fromTag": "1c1448938614", "toUser": "00912269228600", "callid": "[2682298129112022456@121.244.175.56", "cseq": "1 ACK", "userAgent": "Mediant SW/v.7.40A.100.114", "correlationId": "2682298129112022456@121.244.175.56", "node": "remotenode", "dbnode": "remotenode", "selfUri": "/api/v2/telephony/siptraces" }, ........ ...... .......... more results }


    Jerome.Saint-Marc | 2022-11-15 09:48:36 UTC | #2

    Hello,

    Your error probably comes from a mismatch between your Output contract and the successTemplate of your Response configuration. I can't say much as you didn't share them. Note that the JSONPath expression you are using - $.data[?(@.method == 'ACK')].fromUser - will result in an array (of strings).

    Regards,


    garimabalodi | 2022-11-16 05:11:12 UTC | #3

    Hi Jerome ,

    Thanks for your response. That is the issue I suspect but not able to get it work. I am perhaps using a wrong translation map. The intent is to just extract the fromUser and ruriDomain fields from the API response, where the value method == 'ACK'.

    SipTrace-20221116103826.custom.json|attachment (1.8 KB)

    The response I am configuring is:- { "translationMap": { "ruriDomain": "$.data[?(@.method== 'INVITE')].ruriDomain", "fromUser": "$.data[?(@.method == 'INVITE')].fromUser" }, "translationMapDefaults": { "fromUser": "\"UNKNOWN\"", "ruriDomain": "\"UNKNOWN\"" }, "successTemplate": "{\n \"ruriDomain\": ${ruriDomain}\n,\n \"fromUser\": ${fromUser}\n}" }

    Request URL Template: /api/v2/telephony/siptraces?conversationId=${input.conversationId}

    My input contracts are :- { "title": "Input", "type": "object", "required": [ "conversationId", "dateStart", "dateEnd" ], "properties": { "conversationId": { "default": "30b0ad7c-3449-463a-a1ed-b7a93a6577ec", "type": "string" }, "dateStart": { "default": "2022-10-9T15:00:00+0000", "type": "string" }, "dateEnd": { "default": "2022-11-9T15:00:00+0000", "type": "string" } }, "additionalProperties": true }

    Output contracts :- { "title": "Output", "type": "object", "properties": { "fromUser": { "type": "string" }, "ruriDomain": { "type": "string" } }, "additionalProperties": true }


    Jerome.Saint-Marc | 2022-11-16 09:34:30 UTC | #4

    Hello,

    The results of your JSONPath expressions are arrays of strings, and the output parameters are strings. So it is necessary to extract an element from the array. The successTemplateUtils.firstFromArray Velocity macro can be leveraged to achieve this (with a default value to "UNKNOWN") if the array is empty.

    You can keep your Input and Output contracts as they are. And modify the Response Configuration with:

    { "translationMap": { "ruriDomainArray": "$.data[?(@.method == 'ACK')].ruriDomain", "fromUserArray": "$.data[?(@.method == 'ACK')].fromUser" }, "translationMapDefaults": { "fromUserArray": "[]", "ruriDomainArray": "[]" }, "successTemplate": "{\n \"ruriDomain\": ${successTemplateUtils.firstFromArray(\"${ruriDomainArray}\",\"${esc.quote}UNKNOWN${esc.quote}\")}\n,\n \"fromUser\": ${successTemplateUtils.firstFromArray(\"${fromUserArray}\",\"${esc.quote}UNKNOWN${esc.quote}\")}\n}" }

    Regards,


    garimabalodi | 2022-11-16 09:33:58 UTC | #5

    Thanks Jerome,

    It worked perfectly :slight_smile:

    Regards Garima.


    system | 2022-12-17 09:34:29 UTC | #6

    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: 17220