Forum Academy Marketplace Showcase Pricing Features

Passing Dynamic POST Data to External API - Best Practices?


I’m having some problems finding the best way to do this.

I have written an external API to accept JSON data, process it and return a JSON body to Bubble.

BUT… there are a couple things about Bubble I can’t figure out.

I was able to use the External API plugin and set it up to do a POST with JSON body. I filled in my values manually there and did the initial connect to the external API to initialize. Worked flawlessly. My API returned the proper data to Bubble.

Now, what I need to do is the following:

  1. Use DYNAMIC DATA to send to my API using the POST/JSON method. So far, I can’t find any option anywhere inside Bubble to use dynamic data to make a POST request to an external API. How is that done??

  2. When my external API returns the values (all numbers), I need to “modify a list of things” and fill in a bunch of numbers that the API returns. How do I do this? I have a button that can launch the process, but I can’t see in the workflow options how to PASS the dynamic data, nor how to parse the JSON body that is returned or have that JSON data fill in a “list of things” in Bubble. How do you normally do this?

Any tips on best practices would be greatly appreciated. It’s funny I can go write an External API on a Heroku server and have that working just fine but trying to find the options in Bubble to send the POST data and receive the JSON body are stumping me. lol.

Thank you!

If all the data is in the URL then you put the value in brackets in the URL. Then if that item is dynamic make sure the Private checkbox next to that particular url parameter is unchecked. Then when you reference that API whether as an Action or as a Data Source you will be able to use Dynamic Value for the API call. If the parameters are not in the url then you define the parameters below and make sure to uncheck private.

1 Like

You, sir… are a god among men. Thank you!! I didn’t understand how to use the brackets until you showed the example.

That was NOT an easy question by any means. Here are the results of your help:

1 Like

Still just a little stuck parsing the JSON into Bubble.

I have added a list of numbers variable to the Employee “thing” to test this out. To dump all the data from my API into somewhere just to see it’s working. And I keep getting a type mismatch from Bubble.

The RawJSONDump variable was set up as field type Number, with the checkbox checked to make it a “list of multiple entries.”

I’m taking the JSON input from the API (which evaluates as a list of numbers) I and sending it to this list of numbers variable I created, but I keep getting the following type mismatch error from Bubble:

Screen Shot 2021-12-02 at 5.21.14 PM

So, I guess I’m missing one more key ingredient. It doesn’t want me to assign the whole list at once to the list of numbers variable I created in Bubble, I guess. Can I somehow parse the incoming data one item at a time for Bubble to correctly fill in the list of numbers variable I created?

Or… is there a better way to let the incoming JSON data from my external API create a list of numbers all at once?

Thanks again. I think this will be my last question.

Can you change the ‘add’ to ‘set list’ or ‘add list’?

So ‘RawJSONDump set list 2HrAppts - Populate2HrAppointments’s body’

1 Like

That was it! Changed it to “set list” and it was happy.

Do you accept tips by the way? I’m serious. I’m very grateful for your help with this part of Bubble.

My external API output wasn’t well formatted JSON so I am fixing that now. That’s outside of the scope of this forum. But as I was reinitializing the API many times to try things, it seems to have lost its body type as a list of numbers. Not a question just yet. I’m going to work on getting it properly formatted JSON from my API now and re-do the whole thing in Bubble to have it working.

1 Like