API get call doesn't change field in database

Hi guys,

I want to populate one field in my database for a list of hotels with a “GET” call from APIFY.

The field I want to populate is space_rating which is already created as number field in my hotel table.

I’ve also created another field in the same table called gmaps_id which is populated already with the ID from Google. I’m using this row in the DB to match the right hotel with the right rating in the API call.

I have created two backend workflows with two parameters, list type. The flow should look for each hotel, match the gmaps_ids and then populate the space_rating with the right rating from the API call.

This is what I’ve done.

  1. Created two backend flows that are interconnected.

  1. The update_all_space_rating calls the API and then update_one_ranking

  1. And then the update_one_ranking makes the change in the database where IT SHOULD write the ranking, but it doesn’t.

  1. Here are the parameters in the update_one_ranking. I checked them as list as I’m trying to update all hotels with their respective rating. (not sure though if this is the right approach)

  1. I can see the backend flow running and finding the rating, but nothing is being written in that field in the DB.

from that last screen shot with red around space_rating, it doesn’t show a unique ID of a thing to change, so my first thought is that it is not finding the database entry. Either way, I’d suggest setting up like below.

  1. Use only one backend workflow - your update all call is fine to keep and update
  2. First action in the single backend workflow is to run the API call to capture the API call objects list - The backend should have a parameter for a list of the api objects from the call response.
  3. Second action in the single backend workflow is to call a custom trigger in backend to fetch the single database entry needed. - Need parameter and return data both as ‘hotel’ from your database.
  4. Trigger the return data custom event and populate the parameter with Do a search for hotels and constraints for gmapID to equal to result of step 1 first item when result of step 1 is not empty (the is not empty is because that first action to get the api call will have a condition to run only if the backend parameter is empty - signalling the call has not run and/or the entire list is complete).
  5. Return data is equal to the parameter of the custom event
  6. Have action to make changes to things equal to the return data thing and set the rating equal to the result of step 1 first item rating (again do that with in line conditional if the result of step 1 is not empty)
  7. Then schedule your single backend workflow to run again and this time populate the parameter that is the list of objects from api call to be equal to result of step 1 minus item result of step 1 first item.

To make this work your single backend workflow should have an additional parameter that is a counter, where the first time you call it set the counter to 0, and put a conditional on step 1 to only run when the counter is 0 and on each loop set the counter to the counter value plus 1. With this, your first step to run api call only ever runs once for each recursive run you start and you have the parameter that is the api objects to stop the loop when all have been completed (ie: api object parameter is empty and count is greater than 0).

This will allow you to recursively loop over the list of objects successfully and will remove the extra WUs of scheduling and running two sets of backend workflows (saves around 1.4 WUs per api object in the list since it avoids scheduling two backend workflows on each api object)

2 Likes

Thanks Matthew for this detailed explanation. I appreciate the effort. Unfortunately, I don’t understand. I tried to do it step by step but I got very confused and got stuck. Anyway to simplify the explanation?