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.

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.

1 Like


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

2 Likes

This is what the workflow would look like:

1 Like

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.

2 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.