Legacy Dev Forum Posts

 View Only

Sign Up

Outputting an Array of Strings with the Same Type

  • 1.  Outputting an Array of Strings with the Same Type

    Posted 06-05-2025 18:43

    Jacob_George | 2022-08-05 19:15:22 UTC | #1

    I am trying to create a data action that outputs all the company email addresses that have been in a conversation in a specific time interval. The output should be an array with all the addresses. I am using POST /api/v2/analytics/conversations/details/query with the following request body:

    { "interval": "${input.INTERVAL}", "order": "asc", "orderBy": "conversationStart", "segmentFilters": [ { "type": "and", "predicates": [ { "type": "dimension", "dimension": "mediaType", "operator": "matches", "value": "email" } ] } ] }

    That request gives the following 3 results (I've excluded any irrelevant data):

    { "conversations": [ { "participants": [ { "sessions": [ { "addressTo": "example@example.com" } ] }, { "sessions": [ { "addressTo": "example@example.com", } ] }, { "sessions": [ { "addressTo": "example@example.com", }, { "addressTo": "example@example.com", } ] }, { "sessions": [ { "addressTo": "example@example.com", } ] } ] }, { "participants": [ { "sessions": [ { "addressTo": "example@example.com", } ] }, { "sessions": [ { "addressTo": "example@example.com", } ] }, { "sessions": [ { "addressTo": "example@example.com", } ] } ] }, { "participants": [ { "sessions": [ { "addressTo": "example@example.com", } ] }, { "sessions": [ { "addressTo": "example@example.com", } ] }, { "sessions": [ { "addressTo": "example@example.com", } ] } ] } ], "totalHits": 3 }

    The three strings that I would want in the array I am outputting are: $.conversations[0].participants[0].sessions[0].addressTo $.conversations[0].participants[1].sessions[0].addressTo $.conversations[0].participants[2].sessions[0].addressTo

    The problem is that there can be a different number of "totalHits" depending on the time interval that I set in the request body. Is there a way that I can add each addressTo to an array no matter the number of addresses?

    This is as far as I've gotten with the response template, but address_to is a string, not an array.

    { "translationMap": { "addressto": "$.conversations[0].participants[0].sessions[0].addressTo", "numberofconversations": "$.conversations.size()" }, "translationMapDefaults": {}, "successTemplate": "{\n\"address To\": ${addressto},\n\"number of conversations\": ${numberofconversations}}" }

    Thank you!


    Jason_Mathison | 2022-08-05 20:15:18 UTC | #2

    Hi Jacob,

    The magic you are looking for is replacing a specific index with a "*". So

    $.conversations[0].participants[*].sessions[0].addressTo

    Returns an array of values.

    --Jason


    Jacob_George | 2022-08-05 20:15:15 UTC | #3

    That does the trick, Thank you!


    system | 2022-09-05 20:15:30 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: 15810