Outputting an Array of Strings with the Same Type

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": {
    "address_to": "$.conversations[0].participants[0].sessions[0].addressTo",
    "number_of_conversations": "$.conversations.size()"
  },
  "translationMapDefaults": {},
  "successTemplate": "{\n\"address To\": ${address_to},\n\"number of conversations\": ${number_of_conversations}}"
}

Thank you!

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

That does the trick, Thank you!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.