How can we help?
< All Topics

How to display API responses in bot messages?

We have implemented JSON Path to address JSON objects and arrays.

I assume you know how to make an API Call. I will skip to the responses part.

Edit the block where you want the response to be displayed

The format of the message would be {{blockName.JSONObject}}

For example,

You have made the API Call in a Block named “APICall

The response you are getting is a JSON object

"botId": 123,
"categoryName": "Vegetables",
"description": "Fresh green vegetables",
"isActive": true,
"isPopular": true,
"tags": ["food","natural"]

and you want to use the value of categoryName in your message then you will write {{APICall.categoryName}}.

Similarly, the below should work –

  1. {{APICall.botId}}
  2. {{APICall.description}}
  3. {{APICall.isActive}}
  4. {{APICall.isPopular}}

If you have a property or key in the object, whose value is an array(e.g. tags), then you can access the value by using child notations for the array i.e. [index]. For example, the “tags” property has value as an array. For accessing an individual value, use

  1. {{APICall.tags[0]}}

For complex JSON objects, you could first evaluate your JSON at and then use the same address in the botbaba message blocks.

In case, if the call is made in APICall block, and the API’s response is array data, similar to

    "firstName": "John"
    "lastName": "Doe",
    "phoneNumber": [0000000000, 1111111111]

Here, In this case, the response data can be captured by using the “data” key in conjunction with the name of the block in which the API request got made. For example, for the response shown above, to use the property “firstName”, write {{[0].firstName}}.

Similarly, the below should work:-

  1. {{[1].lastName}}
  2. {{[1].phoneNumber[0]}}

Was this article helpful?
3.3 out Of 5 Stars
5 Stars 33%
4 Stars 33%
3 Stars 0%
2 Stars 0%
1 Stars 33%
How can we improve this article?
Previous How to make an API Call from botbaba?
Next How To Forward A Template Message using Botbaba’s Official API and Postman
Table of Contents