Share feedback, ideas and get community help

Updated last week

array posting

I'm making a request to my backend and an array is returned, is there any way for me to map this array and display the result on the screen?
A
E
24 comments
That doesn't look like a Typebot question but a JS question.
If you're willing to display the array on a webpage, you can use the pre HTML tag with your array in it.

If your array contains JSON, you could use JSON.stringify() on each element of the array, inside of a .forEach() loop on your array.
Hope it helps
I have the same doubt, but my array is a dynamic array, the contents change according with the request, in this case, how do I iterate through it and format the data output to Typebot?
Another doubt is how to save the entire JSON from an API request into a variable
When performing an API call with the HTTP Request block, after clicking on Test request, you can map the request's response to one or more variables.
I believe it's always named data but you'd need to test if that's the case.
So to save the entire response as a variable, you'd type data as the value and the name of the variable you want to store it in.

Here's the Documentation link that explains it:
Attachment
save-in-variable.png
What format are you expecting to output to Typebot?
Do you want the values to be outputted as plain text, with the commas?
Is the dynamic array going to be an array of strings, of objects, or can vary?
Hi Anthony, the flow is:

1) Ask a question tô Typebot
2) Typebot makes a HttpRequest to my API
3) My API delivers a variable JSON according with answer in step 1
The problem is here in step 4How do I get the data from a Dynamic JSON to output in Typebot?
In this case, the red box contains a JSON with some records, the BLUE box contains just one value
O can't map to variables because o don't know what structure I Will receive
(Be careful with exposing other people's phone number)
You could use a Script block that uses JavaScript code to loop through the keys and values of your JSON object and format it the way you want it to

I'm pretty sure the API response's JSON's keys would look similar, and same goes to the expected format?
First JSON (generates red box result)
[
{
"produto": "CABO VELA GOL 1.0 CHT 92ED NGK COM PINO",
"estoque": 7,
"preco": 156
},
{
"produto": "CABO VELA GOL 1.0 CHT 92ED NGK COM PINO",
"estoque": 3,
"preco": 156
},
{
"produto": "CABO VELA GOL 1.0 CHT 92ED NGK COM PINO",
"estoque": 0,
"preco": 156
},
{
"produto": "CABO VELA GOL 1.0 CHT 92ED NGK COM PINO",
"estoque": 0,
"preco": 156
}
]
Second JSON (generates blue box result)
Using Dify, it get the both JSONs and makes that output, but I'd like to use Typebot
I think this, but I need to learn more about javascript to deal with this situation where JSON structure is not standard.
It's is the flow that I thought
My API generates a SQL statement based on question and get data from my database, almost all generated JSON is not equals...
[
{
"fornecedor": "DISK ESCAPE COM.DE ESCAPAMENTOS LTDA",
"dataEmissao": "2024-12-05",
"valorParcela": 783.02,
"vencimentoParcela": "2024-12-18"
},
{
"fornecedor": "COMPANHIA BRASILEIRA DE DISTRIBUICAO AUTOMOTIVA S.",
"dataEmissao": "2024-12-11",
"valorParcela": 3735.87,
"vencimentoParcela": "2024-12-18"
},
{
"fornecedor": "COMPANHIA BRASILEIRA DE DISTRIBUICAO AUTOMOTIVA S.",
"dataEmissao": "2024-12-11",
"valorParcela": 2180.15,
"vencimentoParcela": "2024-12-18"
},
{
"fornecedor": "COMPANHIA BRASILEIRA DE DISTRIBUICAO AUTOMOTIVA S.",
"dataEmissao": "2024-12-11",
"valorParcela": 672.45,
"vencimentoParcela": "2024-12-18"
},
{
"fornecedor": "BARROS B.A.P AUTOMOTIVA LTDA",
"dataEmissao": "2024-12-11",
"valorParcela": 6078.11,
"vencimentoParcela": "2024-12-18"
}
]
Okay so from the generated JSON, it seems that what you want the output to process on the JSON is to loop through all the elements in the array (each object) and return the keys and values "as is" in the output, but in a numbered list.

One tricky thing though is that in your last video example, you'd like keys like dataEmissao to return Data de Emissao, which is different from the original key name.

So I assume only the values won't remain the same, but the keys names (that you want displayed) will remain the same (the bolded words before the values in the output).

So a loop should do. Honestly, ChatGPT should suffice to build the script that turns your dynamic data into the output that you want
I will ask ChatGpt to build a script to convert the dynamic result to a readable content. Thanks for your prompt response.
Add a reply
Sign up and join the conversation on Discord