Post an item list in firebase

Hi I need to post an item list in firebase. I want to create a record for each item.
The list is in the variable app (cart) and I want to create the items in the order.
What is the best way to do it?

1 Like

Hi,

This can be done with the following loop:

  1. Check if there’s items in the app variable (e.g. using the LENGTH formula function)
    a) if there’s no items, then you are done and you can stop the loop.
    b) if there are items left, proceed to next steps

  2. Create Record with the first item in the app variable, cart[0]
    a) If this fails, stop the loop.
    b) If this succeed, proceed to next step

  3. Remove the first item in the app var (since it was already created). Use Set app variable flow funciton with the forumla WITHOUT_ITEM

  4. Circle back to the first step.

1 Like

@Cecilia Is there a way to prevent having to loop through every item in the list? This feels like a very wasteful way to create data when many APIs accept posting multiple records at once within a single request body.

I’m trying to figure out how to post a list (the equivalent of GET collection, but for POST) to Backendless, and I haven’t find out how yet! I need my request body to look something like this (notice both objects belong to the same list/array/collection):

[ 
   { "name": "Joe", "age": 24 },  
   { "name": "Betty", "age": 34 }  
]

@Juan_Giraldo unfortunately there’s not a ready-to-go component for creating / updating multiple records at once, although I agree it would be quite useful :confused:

However, if Backendless supports POSTing a list of records, you can instead of using the standard Get / Create / Update / Delete Record flow functions use the HTTP Request flow function. With that you are able to define the request url, request body, request method etc. more freely than with the default nodes, and you should be able to post a list of records :slight_smile:

3 Likes

Hi @Cecilia. I was able to use the HTTP Request flow function to post the list of records to Backendless, thanks! I only assumed there was a default node to post multiple records since there’s also one to fetch multiple records :slight_smile:

2 Likes

I have been looking for this for a long while now. Thank you very much for this.

2 Likes

@Cecilia, Is there a way to choose the documentID of the list being posted to firebase through HTTP?

The body can be a list of objects, sure, but can we post to a URL which is also a list, with specific names for each document?