Goal: Hi, I’m new to Retool and JavaScript! I want to replicate a Python script in Retool and need guidance on how to handle multiple API calls, data manipulation, and transformations using JavaScript.
Steps: I’m trying to build a workflow in Retool where I can fetch sales orders from an API, extract product details for each order, and store the results in a structured format (like a table). Here’s the Python code I’ve been using:
url = "https://%%/api/sales/order?limit=1000"
token = "%%%"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
orders = response.json()
ids = [x['id'] for x in orders]
all_products = []
for id in ids:
url = "https://%%%/api/sales/order/" + id
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers).json()
all_products.extend([
{
"id": product["id"],
"extra_id": product["extra_id"],
"name": product["name"],
"quantity": product["quantity"],
"uom": product["uom"]
}
for product in response['products']
])
df = pd.DataFrame(all_products)
print(df)
How can I achieve the same result in Retool using JavaScript? Any best practices for structuring this workflow in Retool would be greatly appreciated!