Add more than one pair of coordinates from input to Body

I have an input where the user enters addresses. These addresses are saved in a table on the screen as well as in the database. For example, if a user enters 10 addresses, they will be displayed on the screen. I then use geocoding to convert these addresses into a set of coordinates.

There is an API request (POST), to which I need to send not one pair (this is simple and clear), but all 10 at once. I cannot use Bubble to form JSON from these 10 addresses to send them to the dynamic Body field “intermediates” of this request.

I believe there is a simple way to do this, but I have been struggling to find a solution for several days. I haven’t come across a similar answer in the forum either. I would greatly appreciate any assistance on this matter.

As far as I understood you have to send an array (a list of coordinates), includig these 5 parameters at once to the expected server, is that correct? Do you have their API manual? Probably the answer is there.

Hi there! And thanks for your help!

I need to fill out just the 11th line in the Body. So, let’s say I have a user who wants to go from Origin (coordinates A,B) to Destination (A,B) and through 4 Intermediates (A,B; A,B; A,B; A,B). I’m saving all addresses and geocoding them. I do have all As and Bs. The only problem is How do I send all the points in one array? I can’t guess the number of points in advance; it will always differ.

So structuring the array is not the problem, but referencing it?

If so, I mean, if you are saving the geocode in the database, you could create a new field called for example “trip_id”. Hence, when you are doing the post command you can :do search for you data type with constraints where “trip_id” = recently_saved_coordinates.

Same logic would apply if you have to differentiate among origin, destination and intermediate. In this case you should add one more filled like “coord_type” and use and option set to reference if it’s whether an origin, intermediate or final destination coordinate type.

Now, if the problem is how to structure the post API call then we probably should have a look into their API manual.

I think I’ve got your point. You have to set up dynamically the list size, i.e., how many itens (coordinates pair) the array should countain. Is that right? If you wish, you can share with me privatly your app in edition mode. Perhaps I can help.

1 Like

Actually, there’s no problem with sending them the request. They are totally OK to take smth like

{“latitude”: 59.644424, “longitude”: 60.399676}, {“latitude”: 66.08178593030303, “longitude”: 76.63518863333334}

for the intermediates. The only problem is collecting all the pairs in one array like this.

But it looks like you’ve already helped me. I already tried to juggle with Custom states, Backend workflows and even hidden HTML-block on the page. But now I’m trying to save to a temp table coordinates in one field, which should help.

Let me try it. If it doesn’t work, I will give you access cause no more ideas, with pleasure. Thanks again!

I see. Nevermind man. If you’re using custom states you can probably try some append to concatenate the string first and then find & replace to create the correct structure while passing the JSON body and/or try to use the formmated as JSON safe command. Anyway, good luck. If you need help just DM.

1 Like