Hey Bubblers,

It's been a while since I last posted. Life got in the way and I welcomed a new baby into the household.

Today's tip is something that I always struggled with, so I am documenting the solution to help others who face this in future.


Having flexibility in the JSON body of the API Connector

Anyone who has tried using the API connector before knows that documentation is pretty sparse and have banged their head many times on getting a call to work.

The worst thing from this experience is that the error message from Bubble doesn't give enough information on what the API call sends out, making it impossible to debug.

In this case, I was trying to do a POST call with a body as a JSON object, passing in parameters of strings, arrays(a.k.a list) of numbers and a boolean.

The original API call setup

The catch here is that the array and the boolean were optional, therefore I couldn't check the 'allow blank' option.

After a million tries and asking support(who has still not gotten back yet), I found a solution to this which involves formatting the whole body in the workflow:

The improved API call that looks so much cleaner!

Note that only one parameter is left and you will have to put the whole JSON object in the value. If you find it tough to initialize the call, you can also try the 'Manually enter API response' option.

In the workflow, this is how your body json will look like:

Yes, it looks very crazy(and this is already a simplified example).

Here are the steps to follow:

  1. The body is setup with an 'Arbitary text' to make it easier to format the input.
  2. All mandatory parameters are setup at the bottom (remember to omit the comma for the last parameter!!!)
  3. For optional parameters, setup a condition to detect if input is filled, and use "formatted as text" for the output. If there is no input, the output will naturally be empty.
  4. For booleans, this is the setting:
Don't forget the comma at the end as Bubble will never tell you!
  1. For arrays, this is the setting:
Again, don't forget the comma!!!!

If you've gotten this far, you should be able to run a workflow successfully. Don't forget to use the step-by-step debug mode to examine each input. But don't beat yourself up if you can't find the bug. Even a Bubble coach like me regularly gets stuck here, which is why I have written this post as a reminder to myself.

If you need more help, book a session with me at https://bubble.io/coaching.

Subscribe for more content like this!

If you have any questions, let me know via email or my Twitter.