Retool Workflow - Create row in Retool hosted database for each item in object list from GET API request

I am making a GET API request, and the API body response is in the JSON object list.
I am trying to save each list into the Retool hosted Postgres database.

As I am trying to insert a record into the database, I am running into this error:

Can someone advise how I can iterate over each list items and dump it into the database?

The Retool hosted database already has the headers:

  • "Full_Name"
  • "Sub-Department"
  • "Business_Title"
  • "Work_Location"
  • "Last_Name"
  • "Preferred_First_Name"
  • "Start_Date"
  • "Manager"
  • "Reason"

The API response looks something like this:

{
  "Report_Entry": [
    {
      "Full_Name": "John Joe",
      "Work_Email": "john@email.com",
      "Sub-Department": "Engineering : Sup",
      "Business_Title": "Support Engineer",
      "Work_Location": "Amsterdam",
      "Last_Name": "Doe",
      "Personal_Email": "john.doe@gmail.com",
      "Preferred_First_Name": "John",
      "Start_Date": "2024-02-20",
      "Manager": "Jimmy Jones",
      "Reason": "New Hire"
    },
    {
      "Full_Name": "Aaron Carter",
      "Work_Email": "aaron@example.com",
      "Sub-Department": "People : Recruiting",
      "Business_Title": "Principal  Recruiter",
      "Work_Location": "Tokyo",
      "Last_Name": "Carter",
      "Personal_Email": "aaron.carter@gmail.com",
      "Preferred_First_Name": "Aaron",
      "Start_Date": "2024-02-05",
      "Manager": "Joe Jones",
      "Reason": "New Hire"
    }
]
}

Have you tried a loop block?

1 Like

It looks like you have an "INSERT" statement being generated in the JavaScript. You don't need to do this (or a loop). Just pass the returned arrays to the Retool Database block. In the DB block, switch to "GUI", select your table, drop down the action to "Bulk Insert Records", and you should be good to go.

1 Like

Thank you!
This helped! and also I had my Postgres database headers all in lower case.