API null value instead of empty

Hello,

I am trying to send an empty value to Postmark, but the bubble is sending null.

How can I send an empty field instead of null? I have been trying to solve this for the day now with no success.

1 Like

Uncheck the ā€˜allow blankā€™ in the API connector. This sends ā€˜nullā€™ if it is empty. Alternatively, you can always do a condition that says ā€˜if the value is empty send a space insteadā€™ so itā€™s not empty.

Normally when creating the API call, if something can be empty, instead of putting the value like this:

"companyDivision": "<companyDivision>"

I would do this instead:

<companyDivision> then in the value I would do this "companyDivision": "<companyDivision>" so that in the workflow, the whole part can be dynamic, if it is empty, donā€™t put anything in it.

2 Likes


Like this for example. I donā€™t want to have a CC each time. Just sometimes.

3 Likes

This is what the workflow would look like:

2 Likes

Thank you very much for your reply. I found a solution 5 minutes ago, actually, so I will write it here so everyone can see if they have a similar issue.

The main issue is that I was trying to send my values like this:

"companyDivision": "<companyDivision>"

, which should have been done differently. Instead of writing the previous code, write this one:

"companyDivision": <companyDivision>

And do not use ā€œā€. The reason to do so is that bubble is writing null for the empty string, which postmarks read as empty, but when you have ā€œā€, it literally sends the text ā€œnullā€.

The next thing to do is, when you are assigning value to in any workflow, make sure that you write dynamic value:formatted as json safe. If you assign :formated as json safe, the bubble will add ā€œā€ automatically if there is any value.

I hope that Iā€™ve explained it so it can be understood. If anyone canā€™t, feel free to message me.

5 Likes

I am confused and I couldnā€™t find answers throughout the forum. Will appreciate if anyone could shed some light.

1.) Can you achieve the same without explicitly constructing the JSON body?
(First, I use a NoCode platform to reduce the need of hardcoding. Second, everytime I update the JSON body I have to reset all the params settings)

2.) For dynamic data, eg, from a Inputā€™s value, it just wouldnā€™t send an empty string nor null. If I tick optional, the request skip the field. If I donā€™t tick optional, either ā€œallow blankā€ or not refuse to accept the empty value.

Context: I am writing an API call for a PUT request. I want to be able to set something to empty.

Thanks you!

  1. Unfortunately, it is how it isā€¦ I had the same problem that I had to reset all the parameters. But yes, you need to use JSON body if you want full customization.

  2. If it is empty, it will not send anything. What are you trying to achieve?

Thanks for the reply!

I am just building a simple form to send a PUT request to my Django backend to update the model.

So very intuitively if my user empties out a an input field, letā€™s say, ā€œremarksā€, I would be able to send a json body of

{ ā€œremarksā€:ā€ā€}

So my backend updates the remarks to an empty string.

However, in the bubble app, if the user empties the input field, bubble just gives an error saying Params remark cannot be empty. (whether allow blank is checked or not)

I know I can get it working by building the JSON body myself, but it will bring inconsistency among API params in workflows.

For example, for these kind of custom constructed JSON body, you need to enclose with ā€œā€; for calls using bubbles default form, you shouldnā€™t, otherwise it will wrongfully send extra ā€œā€.

(Updates: as you said, ā€œjson-safeā€ is better than enclosing with ā€œā€. But it gives the same problem of extra ā€œā€ when paired with default calls)

The inconsistency will make maintenance and collaboration very hard. Meanwhile I also donā€™t want to refactor all my other 30+ api calls to work this way.

Iā€™m just surprised there isnā€™t a way just to send an empty string from an input field without workarounds.

This is cool, but does it work if you are doing body type: raw?

ā€œcustomerā€: {
ā€œfirst_nameā€: customer_first_name,
ā€œlast_nameā€: customer_last_name,
ā€œemailā€: customer_email_1,
email_subscribe
ā€œtagsā€: customer_tag

If I initialize with nothing in there and allow blank = true I get bad requestā€¦

Hmm :thinking: @neilmagnuson11

In the workflow are you doing ā€˜formatted as JSON Safeā€™?

Oh, and if you initialize you have to have something there temporarily. Once initialized you can delete the values.

Thanks for the tip on initialize temporarily.

Here is what I have:


No means its null, not showing on the screen at all for the user to click.

The yes works, but when its no i get a weird error:

Any ideas?

Instead of removing the line, you can keep the key and just set the value
So in json it will be "buyer_accepts_marketing":_*_email_subscribe_*_,
In the dynamic field, you keep :format as text
On yes: true
on no: false OR null
However, it actually hard to tell you whereā€™s the error. You have a lot of field, be sure to encode them correctly using :format as json-safe if needed.
Also, donā€™t forget to set the content-type header to application/json

Sometimes, to make it easier to figure this sort of thing out, I suggest using Arbitrary Text for everything. Then you can also save the arbitrary text into your database. That way, you can take it and put it in a JSON validator to see what the issue is. It might be a comma that is there that shouldnā€™t be if the value is empty. You might be able to see the data in the Bubble Logs possibly. Can you see all the data somewhere and see what it is actually being sent?

Had to comment to this because it helped me for my Supabase backend workflow, and for anyone searching on the solution. Thank you so much @J805

@faisalkarimstubapp So glad that helped. :blush:

And this one from @zoombackdrops is a really great solution as well. Thank you for pointing this out. It helped with my Supabase backend.

1 Like

Does anyone have any suggestions on how to return ā€œnullā€ when using the Return data from API function?

Can you share a print screen?