How can I print object/array datatype variable?

How can I print object/array datatype variable , I have been using various variables which need to displayed either in email or in bot response.

1 Like

You can use the following syntax to access variables in the bot:

  • Object: {{{variables.variable_name.key}}}
  • Array: {{{variables.variable_name.index}}}

I am using travel advisory API, the output is in below format -

{

"api_status": {

    "request": {

        "item": "us"

    },

    "reply": {

        "cache": "cached",

        "code": 200,

        "status": "ok",

        "note": "The api works, we could match requested country code.",

        "count": 1

    }

},

"data": {

    "US": {

        "iso_alpha2": "US",

        "name": "United States",

        "continent": "NA",

        "advisory": {

            "score": 3.3,

            "sources_active": 4,

            "message": "United States has a current risk level of 3.3 (out of 5). We advise: Use some caution when travelling United States.",

            "updated": "2022-01-26 08:29:24",

            "source": "https://www.travel-advisory.info/united-states"

        }

    }

}

}

============================

I want to fetch the message for any of the country, for that I am using below format.

{{{variables.vtraveladvisory.data.US.advisory.message}}}

here I have to hardcode US or any other country for which we want to get the travel advisory. How can we dynamically pass the country name in the {} without hardcoding it so that whenever user passes the country code it automatically shows the travel advisory for that country

1 Like

It seems like you need to write a transformation function to parse the API response. You can learn more about the transformation function here: Transformation Function | yellow.ai