T
Typebot•5mo ago
gk

Storing and displaying arrays returned by an API

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?
{
"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
}
]
}
]
}
{
"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
}
]
}
]
}
7 Replies
Michaelvips
Michaelvips•5mo ago
Did you already try Save in variables ?
No description
Baptiste
Baptiste•5mo ago
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. Here is what I did: https://app.typebot.io/typebots/cluwg7tvc0001106bdrjxlc6j/edit Let me know if it makes sense
gk
gk•5mo ago
That's exactly what I wanted. Thank you very much 🫡
pedro
pedro•4mo ago
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?
gk
gk•4mo ago
Make sure you made the right block connections with the arrows as it seems you caused an endless loop
pedro
pedro•4mo ago
I guess that the arrows are fine I'm using some JSON data as you did in the Sales example. What am I missing? 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?
Kristina
Kristina•4mo ago
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!
Want results from more Discord servers?
Add your server