Genesys Cloud - Main

 View Only

Sign Up

Expand all | Collapse all

Best practices for translation maps and Velocity macros in Data Actions

  • 1.  Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-23-2026 16:25

    Hi everyone!

    I've been working with Genesys Cloud Data Actions and would like to learn how others use translation maps and Velocity macros to handle API responses.

    How do you decide what to extract with JSONPath in the translation map and what to transform in the success template? I'm especially interested in approaches for nested objects, arrays, dynamic keys, and optional fields.

    The Genesys documentation shows useful macros such as firstFromArray and moveKeysIntoArrayOfObjects: https://help.genesys.cloud/articles/velocity-macros-data-actions/

    If you have examples or tips from your own Data Actions, I'd love to hear them. Which macros have been most useful to you, and what challenges have you encountered?


    #API/Integrations

    ------------------------------
    Fábio Vieira
    ------------------------------


  • 2.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-23-2026 16:58

    Hello Fabio, 

    A useful way to approach this is to use the translation map to extract the values or objects you need from the API response with JSONPath, and then use the success template to help shape those values into the format required by your success schema.

    I found for arrays, `successTemplateUtils.firstFromArray()` can be useful when you only need the first result. For responses with dynamic keys, `successTemplateUtils.moveKeysIntoArrayOfObjects()` can convert those keys into a structure that Architect can work with.

    For optional fields, `translationMapDefaults` can also help when a JSONPath expression doesn't resolve a value. One thing to note is that a resolved `null` value does not trigger the default.

    The Velocity macros documentation has examples of these:
    https://help.genesys.cloud/articles/velocity-macros-data-actions/

    The response configuration documentation is also useful for understanding how translation maps, defaults, and success templates work together:
    https://help.genesys.cloud/articles/response-configuration-data-actions/

    I would love to hear examples from other Community members on how they are handling more complex responses, especially nested arrays and dynamic keys!

    Cheers,



    ------------------------------
    Cameron
    Online Community Manager/Moderator
    ------------------------------



  • 3.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-23-2026 20:44

    Hi Fábio,
    My general approach is to use the translation map to extract and name values from the API response, then use the success template to construct the final JSON that must match the output contract.

    For example, if an API returns:

    {

      "tickets": [

        {

          "id": "ABC001",

          "status": "Assigned"

        },

        {

          "id": "ABC002",

          "status": "Pending"

        }

      ]

    }

    A simplified response configuration could be:

    {

      "translationMap": {

        "ticketIds": "$.tickets[*].id",

        "ticketStatuses": "$.tickets[*].status"

      },

      "translationMapDefaults": {

        "ticketIds": "[]",

        "ticketStatuses": "[]"

      },

      "successTemplate": "{\"ticketIds\":${ticketIds},\"ticketStatuses\":${ticketStatuses}}"

    }

    The output contract would then define ticketIds and ticketStatuses as string collections.

    We used a similar approach for a ticket lookup action that returns multiple ticket numbers, statuses, descriptions, assigned groups and URLs to a Genesys script. The main challenge was ensuring that the collections remained aligned when optional fields were missing.

    firstFromArray is useful when JSONPath returns an array but only one value is required. moveKeysIntoArrayOfObjects is useful when identifiers are returned as dynamic object keys rather than normal properties.

    For deeply nested or highly dynamic responses, I have found it easier to normalise the response in a Genesys Function or middleware first and keep the Data Action contract simple.

    This Community discussion has a useful nested-array example using firstFromArray:

    https://community.genesys.com/discussion/nested-array-translation-map-issue-conversation-details

    This post also provides a complete example of using a translation map and success template to retrieve participant data:

    https://community.genesys.com/discussion/data-action-to-gather-participant-data-help-needed

    Official Velocity macro documentation:

    https://help.genesys.cloud/articles/velocity-macros-data-actions/



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 4.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-24-2026 04:44

    Hello Fabio,

    It depends on where you use the data action
    From Architect, it is easier because you can format data to match your need (String Collections, Parsing...)
    From Outbound or scripts, it is more complex !

    You might be tempted to ask AI for a DA structure, but they rarely does the job because Velocity is not completely supported so you have to find shortcuts to make it work

    Working with arrays, you often only want a single response out of an array
    you can use filters to request one
    Example:
    "ServiceIdArray": "$.participants[?(@.purpose ==\"customer\" || @.purpose ==\"user\" || @.purpose ==\"external\")]attributes.MyData"

    And you want the first element if exists:
    "successTemplate": "{\"InfoService\": #if(${ServiceIdArray}!=\"[ ]\")${successTemplateUtils.firstFromArray(\"${ServiceIdArray}\")}#else\"None\"#end}"

    Now if you need an array in Architect, you can pass it as a JSON string form in DA:
      "translationMapDefaults": {
        "ParticipantIdArray": "[\"\"]"
      },
      "successTemplate": "{\"agentparticipantid\":\"$esc.jsonString(\"${ParticipantIdArray}\")\"}"
    And then recreate a string collection under architect:
    Split(Trim(Replace(Replace(Replace(Flow.participantid, "[", ""), "]", ""), "\"", "")), ",") => Collection String

    From there, you can access element in a loop
    Trim(GetAt(Flow.participantList, State.IndexLoop))

    If you have a specific JSON object you want to parse, I am sure we can help you find out a way to read it in a DA

    Regards



    ------------------------------
    Charles-Henri
    Consultant Customer eXperience
    ------------------------------



  • 5.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-24-2026 15:56

    Hi Charles,

    Thanks for sharing these examples! I liked your point about how the approach changes depending on whether the Data Action is used in Architect, a script, or outbound.

    Filtering the array in the translation map and then using firstFromArray in the success template is a great practical example. I’m interested in seeing more ways people use translation maps and Velocity macros in their day-to-day work, especially for responses that need some transformation before they can be used.

    Are there any other macros or patterns you find yourself using often?

    Thanks again!



    ------------------------------
    Fabio Vieira
    ------------------------------


  • 6.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-26-2026 17:42

    Hi Charles-Henri Vannimenus!

    Thanks for sharing. Your observation was very useful to me.



    ------------------------------
    Juliano Fernandes Mendes Pimentel De Paiva
    Genesys Analyst
    ------------------------------



  • 7.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-24-2026 13:49

    Thanks for sharing this! Really helpful insights, especially around handling arrays, dynamic keys, and optional fields in Data Actions.

    I appreciate you taking the time to share your experience!



    ------------------------------
    Gustavo Nogueira
    CX - Data Analyst
    ------------------------------



  • 8.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-24-2026 15:14

    Thanks, Gustavo! I'm glad it was helpful. I'd be curious to hear more about the scenarios where you use Data Actions in your day-to-day work. What kinds of challenges come up most often for you?



    ------------------------------
    Fabio Vieira
    ------------------------------



  • 9.  RE: Best practices for translation maps and Velocity macros in Data Actions

    Posted 09-24-2026 15:41

    Thanks! In my day-to-day work, I mainly use Data Actions to connect Architect flows with external APIs, retrieve customer or interaction information, and sometimes validate or update data during the customer journey.

    One of the most common challenges is dealing with API responses that were not designed with Architect in mind, especially nested objects, arrays, optional fields, and inconsistent response structures.

    Another challenge is keeping the Data Action simple enough to maintain. Sometimes the API response contains much more information than the flow actually needs, so deciding what should be extracted in the translation map and what should be transformed in the success template becomes really important.

    That's why examples around JSONPath, arrays, and Velocity macros are always useful for me.



    ------------------------------
    Gustavo Nogueira
    CX - Data Analyst
    ------------------------------



  • 10.  RE: Best practices for translation maps and Velocity macros in Data Actions
    Best Answer

    Posted 09-25-2026 10:04

    Hi Fabio,

    If the size of the JSON response isn't too big, and you are only going to use the Data Action responses in Architect and NOT in scripts, then I have found that returning the entire JSON response to Architect and using the new-ish JSON functions in Architect are much easier than building out success templates.

    For instance, if you call the Genesys Cloud API to get the conversation JSON, GET /api/v2/conversations/${input.conversationID}, then you can return the entire JSON response payload to Architect using a success template like this:

    {
    "translationMap": {
    "conversationJSON": "$"
    },
    "translationMapDefaults": {},
    "successTemplate": "{\"conversationJSON\": \"$esc.jsonEncode(${conversationJSON})\"}"
    }

    Then you can use the Architect JSON functions to parse and navigate the JSON as needed.

    There are limits to the size of a string that you can return from a Data Action to Architect, but you might find that this works for you, and I find it much easier than messing around trying to get a translation map to parse the JSON in the way that I want.

    Another alternative is to use Genesys Cloud Function Data Actions.  If you have development skills or access to an AI platform, then you can pretty easily generate an AWS lambda package that makes the API call you want and parses out the data that you want and then you just upload the zip file into the Function Data Action configuration.  But I would suggest Function Data Actions only where the parsing is especially complex.

    Good luck.



    ------------------------------
    Jim Crespino
    Senior Director, Developer Evangelism
    Genesys
    https://developer.genesys.com
    ------------------------------