https://discord.gg/botpress logo
Store api response as a variable
# 🤝help
p
What is the proper way of storing the response of a get request made in the "HTTP requests / API calls" card? I am currently passing the response into the input task of an ai task card and instructing it to copy the data from the response to a variable named 'theData'. The issue with this is it never populates the variable 'theData' after the second time it runs. If i run this same setup in the main work flow it works, if i transition out of my main works flows autonomous node into a sub work flow and try to store the respons ein a variable via ai task its leaves the var 'theData' empty the first time it runs. Sooo confused lol
m
If you know how the body of the response looks like just do it via execute code
AI tasks aren't deterministic
p
Using an execute code card is the recommended approach. To find out how your response looks like you can enter it in a text card. Hope this helps!
g
just add this at the bottom of your execute card:
workflow.theData = response.data
or whatever your response var is named.
put that wherever it makes most sense in your code.
s
do you need to define the "workflow.theData" variable first? and if so, I can't see a JSON option?
p
p
Thank you everyone for your kind and helpful responses, an execute code card was perfect way for handling api response, much faster and no llm! Onto the next workflow!
n
Thanks guys, I learned something new 🫶🏻
3 Views