API call only runs on first row of data - how can I make it loop through each row?

  • Goal: Have an API enrichment loop through the values of each row in a table and update the table back with the results from the API.

  • Steps:

What's working

  • Dynamically import a file upload to a table
  • Make an API call to an external platform when a trigger button is selected
  • Update the response back in the table.

What's not working

  • While I'm able to make an API call, only an API call is made for the first row.
  • While I'm able to update the response back to the table, it's populating the answer for the first API call to all rows instead of just the first row.

I want to be able to loop through the rows of the table and make an API call for each website, and then have the output updated back to the GPT Scraper column of the table.

  • Details:

API Call

{"instructions":"{{gptScraperForm.data.gptInput }}","linkSelector":"a[href]","maxPagesPerCrawl":0,"model":"gpt-4o","openaiApiKey":"xxx","proxyConfiguration":{"useApifyProxy":true},"removeElementsCssSelector":"script, style, noscript, path, svg, xlink","removeLinkUrls":false,"saveSnapshots":true,"schema":{"type":"object","properties":{"title":{"type":"string","description":"Page title"},"description":{"type":"string","description":"Page description"}},"required":["title","description"]},"startUrls":[{"url":"{{table1.selectedRow.Website}}"}],"useStructureOutput":false,"includeUrlGlobs":[],"excludeUrlGlobs":[],"maxCrawlingDepth":99999999,"initialCookies":[],"temperature":"0","topP":"1","frequencyPenalty":"0","presencePenalty":"0","pageFormatInRequest":"Markdown","skipGptGlobs":[],"dynamicContentWaitSecs":0}```

Transformer


function transformData(data) {
  const gptResults = data.map(item => item.answer).join('\n');
  {{ gptScraperResults.setValue(gptResults) }};
  return gptResults;
}

return transformData(data);

return da```

Screenshots

API Call

This successfully makes the API call and returns the correct data, but it is only taking the website from the first row. I want it to call the API for each website in the table rather than just the first website.

Success Event Handler

Dynamic Column Value from API

This is taking the API result from the first row and populating the first result to all rows.

1 Like

A post was split to a new topic: Dynamically populate dropdown within listView containers

Bump

Hey @Patrick_Hoban - thanks for reaching out and for providing such thorough documentation!

Just to make sure we're on the same page, I'm going to summarize my understanding of your app below. Correct me if I have any parts of this wrong!

  1. Upload a file.
  2. Save parsed contents of file to a global variable.
  3. Connect table to global variable.
  4. Define some enrichment query.
  5. On trigger, execute enrichment query for each row of the table.
  6. Update global variable (and thus the table) on success of each enrichment query.

I have a few clarifying questions, as well:

  • Are you currently passing the entire data set into the query?
  • If so, have you verified that you get a full set of responses back?

My goal with these questions is to hopefully narrow down where the issue lies. Once we do that, it should be a quick fix!