REST API Array Response > Single Object from Array Selected in List View > Update retool DB

Hi all,

First time posting - LOVING RETOOL!!!

So here's where I'm stuck...

  • I have a REST API response
  • The raw data in the response includes a unique ID called quoteId
  • I am writing this to my RETOOL DB in an earlier query.
  • My DB is set to read & write
  • I have fields in my DB appropriately named for each element within the object of the API response.
  • I am transforming the parts of the response, that I wish to use, into an array:
    "size": "large",
    "itemId": "123",
    "averageWeight": 500,
    "colour": "pink"
    "price": 20,
    "name": "Watermellon"
    "size": "medium",
    "itemId": "456"
    "averageWeight": 400,
    "colour": "orange"
    "price": 10,
    "name": "Cantelope"
    "size": "small",
    "itemId": "789"
    "averageWeight": 100,
    "colour": "yellow"
    "price": 5,
    "name": "Banana"
    "size": "small",
    "itemId": "xyz"
    "averageWeight": 100,
    "colour": "orange"
    "price": 2.5,
    "name": "Orange"
  • I am displaying each fruit in its own container in a List View
  • There is a button within each container (one button for each fruit)
  • I have an event handler to run a 2nd query
  • The 2nd query is where I am stuck
  • It needs to update the existing DB record based on the unique quoteId with a single item selected via the button
  • Only 1 fruit is ever selected
  • Im am trying to use the GUI mode (helper text says this is the best for write)
  • Filtering by quoteID
  • Changeset = Key value pairs

Trying to do something like this with my Key value pairs:
size >{{REST API['0'].size}}
item_id >{{REST API['0'].itemId}}
average_weight >{{REST API['0'].averageWeight}}
colour >{{REST API['0'].colour}}
price >{{REST API['0'].price}}
name >{{REST API['0'].name}}

And it works except I'm unsure how to change the ['0'] to reference which button was clicked within the container of the list view for the selected fruit?

Ok... figured this out...

  1. I added a variable called selectedFruit
  2. I added an event handler to the button within the list view container (list view shows the user a button for every container). The event handler sets a variable {{i}} (simply the number of the object within the array REMEMBER the first object in an array = 0, 2nd = 1, 3rd =2 etc)


  1. I then use this variable in my key value pairs within my write to retool DB query...

size >{{REST API[selectedFruit.value].size}}
item_id >{{REST API[selectedFruit.value].itemId}}
average_weight >{{REST API[selectedFruit.value].averageWeight}}
colour >{{REST API[selectedFruit.value].colour}}
price >{{REST API[selectedFruit.value].price}}
name >{{REST API[selectedFruit.value].name}}

1 Like

Thanks for posting your solution, @marty_pocock Glad to hear you're loving Retool! :tada: