Loop trough customer, run query and post in right DB - Array / Object problem

Hello!

I have a table named customers and from the api i get them, their adresses comes with a link instead of pure data for ex. each adress, city, postcode etc.

I got it working so i can loop trough each id of that table and get the data, but not sure how i can connect that data to the right customer?

3fd7c9127a8dd060b3665318c18cf5a6
def324e068c206975125595aaa8a94d9

Is there a way i can write it straight to the Retool PostgreSQL on a new DB or fill in columns in the Customer DB?

I'm trying to use {{queryAdresses22.data[1].value.postalAddress}} to post to DB, but it gets back as an object which is not valid, and if i'm using only {{queryAdresses22.data}} i get the value instead of each details. Might be easy with an transformer or some kind?

Hey @Jonnalo!

You can await the call to your API to access the query data right away in that promise, which may help :thinking:

What if you did something like:

return Promise.all(
   allCustomerSort.data.map(async (row) => {
      //get address data
      const address = await CustomerAdres.trigger({...});

      //assign so that row values will overwrite address values when they're the same (e.g. id)
      //you can totally use a more nuanced assignment here though
      return Object.assign(address.value.postalAddress, row);
   })
);

I'm particularly curious about that id it looks like the customer id and postal address id are different from your screenshots, but does the postal address data have any field that connects it back to the customer?

Perfect, thanks a lot! That solved it.

return Promise.all(
   allCustomerSort.data.map(async (row) => {
      //get address data
      const address = await CustomerAdres.trigger({      
        additionalScope: {
        customerid: row.id,
      }});

      //assign so that row values will overwrite address values when they're the same (e.g. id)
      //you can totally use a more nuanced assignment here though
      return Object.assign(address.value.postalAddress, row);
   })
);

I can now use this output into DB instead of split as normally thought.

It is as you say, which made me go very confused. The customer has one id, and adress another id. When i use GET postaladress, on user id - i only get adress ID. So the only connection is that customer has postal id but not back. I do have one other connection but its not 100% the same, customer has Name and postal have displayName, which then includes name + adress. So still, kinda confusing.