Share feedback, ideas and get community help

Updated 10 months ago

Storing and displaying arrays returned by an API

At a glance

The community members are discussing how to store and display a JSON API response containing sales data with associated products and prices. One community member suggests saving the sales data in variables and parsing it with JSON.parse, but notes that this is not the easiest approach due to the nested product data. Another community member shares a solution using a tool called Typebot, but some users encounter issues with the solution, such as an infinite loop and a timeout error. The discussion also includes a request to create buttons from the product data that include an image, product name, and a link to the product page.

Useful resources
Hi, guys.

Suppose I have the following JSON as an API return and would like to store and display (in one or more text bubbles) each sale with their respective products's prices. What's the best way to do this?

Plain Text
{
  "sales": [
    {
      "id": 1,
      "name": "sale 01",
      "products": [
        {
          "id": 1,
          "name": "product 01",
          "price": 2.32
        },
        {
          "id": 2,
          "name": "product 02",
          "price": 5.99
        }
      ]
    },
    {
      "id": 2,
      "name": "sale 02",
      "products": []
    },
    {
      "id": 3,
      "name": "sale 03",
      "products": [
        {
          "id": 1,
          "name": "product 01",
          "price": 2.25
        }
      ]
    }
  ]
}
2
m
B
g
13 comments
Did you already try Save in variables ?
Attachment
image.png
Mmmh that's a good question!
Since, there is products which is a nested list, we would be obligated to save the sales list in a variable and later on parse it with JSON.parse
So that's definitely not the easiest use case. It needs a bit of code.
Let me know if it makes sense
That's exactly what I wanted. Thank you very much 🫡
Hi guys, I tried the example that @Baptiste showed, but I got this instead:



An error occurred while loading the bot.

{
"status": 408,
"body": {
"message": "15 seconds timeout reached",
"code": "TIMEOUT",
"data": {
"code": "TIMEOUT",
"httpStatus": 408,
"path": "startChatPreview"
}
}
}

Is this an connection error from my machine?
Make sure you made the right block connections with the arrows as it seems you caused an endless loop
Attachment
image.png
I guess that the arrows are fine

I'm using some JSON data as you did in the Sales example. What am I missing?
Attachment
image.png
I've been testing here, and the problem is that this infinite loop that you've mentioned @gk occurs when I connected the arrows, like this:
Without this connection I can run the bot, but without the value in the "Waste name" variable. Any ideias on why the script is not running?
Attachment
image.png
Hi guys, I would like to join the conversation because it aligns with what I am looking for. I am interested in knowing if it is possible to create buttons from the product data, which would include an image, the product name, and a link/button to the product page.

Thank you for helping!
Add a reply
Sign up and join the conversation on Discord