Help Troubleshooting Workflow SQL>JS>API>API

Hi everyone, long time retool users and early workflow user. I am kinda stuck on how to do something in workflows which I am manually doing in a retool app now. I find myself sandbox test as an app first and than build workflows from that.

The canvas looks like this

Basically I am filtering a product catalog via snowflake, I want JS to loop through the data and trigger 2 API calls. They are using AI to do some writing. From there I want the final add_product api call to add the product to our ecommerce store using our API where it takes some values from the snowflake data set as well as the values from ai and ai_meta API calls.

Anyone done something similar and could help steer me in the right direction?

Hi @seandawes Welcome to workflows! :tada: Thanks for reaching out.

It looks like you'll want to use a loop block, and in the loop, call those 3 queries. I would suggest making ai, ai_meta, and add_product functions (you can add those in the lefthand menu) and then have the JS block call them. e.g. the JS block could look like

for (const row of {

const a = await ai(..)

const b = await ai_meta(..)

await add_product(


Let me know if that helps! Happy to take another look. Also, I checked internally, and we're actually working on an easier way to do this, so keep an eye out for workflows updates later in the quarter

I am still kinda stuck. Currently this is the canvas

If I were to move them to functions like you suggest it would look like the following?

But for the JS loop block I am unsure how to pass the results of each api call back to the final function which is the add product api call

for (const row of {

const a = await function_ai(row.CLEANED_TITLE)

const b = await function_ai_meta(row.CLEANED_TITLE)

await function_add_product(?)


And in the function which is the add product api call how would I reference variables from the row loop from my initial SQL data table as well as the 2 openai API calls in the loop?

Am I safe to assume we can call a function within a JS block of the workflow to trigger an API call like this?

for (let i=0;i<;i++){
 await function_add_product({

@Tess Ok so here is where I am at. Everything works BUT passing the value's of the 2 restAPI calls

The console.log is showing me that it has the values for const a and const b

for (let i = 0; i <; i++) {
   const a =[i].choices[0].text.replace(/\n/g, ' ');
  const b =[i].choices[0].text.replace(/\n/g, ' ');

  const c =[i];

  const payload = {
    title: c.CLEANED_TITLE,
    sku: c.SKU,
    mpn: c.MFG_NUMBERS,
    brand_id: c.BRAND_ID,
    description: a,
    meta_title: c.CLEANED_TITLE,
    retail_price: c.PRICE


  await function_add_product(payload);

Hi @seandawes

Can we see the function too? How are the params set up?

Since we have values for const a and const b, I'm curious if it is working, but there is no data specifically returned?


Here's an example: