API Connector - Hide an entire line of json if a parameter is empty?

Hey friends,

I’m trying to figure out if there’s a way to remove the entire line of a json request if it’s empty. For some the apis I’m working with, sending empty or null parameters will cause an error, so I’d like to just “erase” that line if the parameter doesn’t have any data.

For instance, if I don’t put the parameter “image” in this request, I want it to show like this:

{
“version”: “d830ba5dabf8090ec0db6c10fc862c6eb1c929e1a194a5411852d25fd954ac82”,
“input”: {
“prompt”: “<prompt_text>”,
},
}

But if I do have the parameter image, I want it to show like this:

{
“version”: “d830ba5dabf8090ec0db6c10fc862c6eb1c929e1a194a5411852d25fd954ac82”,
“input”: {
“prompt”: “<prompt_text>”,
“image”:"<image_url>"
},
}

Right now, it just puts null or an empty string, which causes many of the apis I am using to fail.

As a workaround, I’ve just been creating multiple calls with different options, but that’s obviously unweildy with more than a few optional parameters that need to be removed from the call if they’re blank.

Remove the quotes. “null” is not the same as null. When you are in composer use field value’s is empty :format as text. In the true, put null. In false put “field value”.

If the API doesn’t accept the null at all (rare), set all the line “parameter”:“value”, (be carefull about the comma) and use the same function vut in false, but the whole line including comma if needed (I prefer to put theses fields not at the end and always add a comma). In true, leave empty.

@Jici The api then fails with “expected string and got null”

Can you explain more what you mean by:

If the API doesn’t accept the null at all (rare), set all the line “parameter”:“value”, (be carefull about the comma) and use the same function vut in false, but the whole line including comma if needed (I prefer to put theses fields not at the end and always add a comma)?

Do you have an example of a call using this method? Are you literally just building the call programatically using bubble?

Do this instead:

{
“version”: “d830ba5dabf8090ec0db6c10fc862c6eb1c929e1a194a5411852d25fd954ac82”,
“input”: {<image>
“prompt”: “<prompt_text>”
},
}

Now you have a parameter image to fill in, so make it
[your image source]:is not empty:format as text

For “yes”
“image”:"[your image source]",

For “no”, leave blank

Kind of yea, putting in whole lines depending on if the value is empty or not.

I’ve updated my answer but @tylerboodman is right If you choose to replace the hole line, leave true empty.

1 Like