Data Source API JSON Safe Parameter Difficulty

Hello Everyone,

I’ve encountered a recurring issue when using APIs as data sources and was wondering if anyone knows of a fix.

I usually set the parameter to be formatted as JSON safe. I’ve noticed that Bubble often sends API requests with blank parameters when doing this.

This happens when the parameter variable hasn’t loaded yet. Despite setting these parameters to reject blanks (by unchecking “allow blank” in the API connector), Bubble interprets an uninitiated variable as "\ "\ “”, effectively bypassing this restriction.

This situation leads to several problems: unnecessary API requests that consume WU and increase costs with the API provider, as well as the premature triggering of events. Specifically, I use a custom plugin that processes this data source and initiates an event whenever the input value changes, which is inadvertently activated by these requests with blank parameters. Below are some screenshots showing this:

Correct Call:

Incorrect Call:

Thanks!

I’m not sure if this will help, but when formatting as JSON safe, bubble always wraps the strings in “” , so, you can either remove the front and trailing " or only format as JSON non-empty strings.

As you can see, all your parameters are wrapped in quotes

Can you show a snippet of the bubble action?

Thanks @DjackLowCode - I actually am not supplying quotes in my initial input of the parameters, however. The values are text fields stored in the database I am simply formatting them as JSON safe, and they are stored in the DB without quotes.

My hunch is that behind the scenes, bubble is calling JSON.stringify twice on the inputs, in order to escape all the reserved characters, or something like that, and that is resulting in some weird happenings with empty parameters.

Hi @doug.burden ,

It is actually an API being used as data, below is a snap though of the parameters:

Never had a scenario that led to this issue but could you use Get course from Page URL's Languages voices:random item is empty formatted as text? When yes, leave it blank.

When no, Get course from Page URL's Languages voices:random item:formatted as JSON-safe

2 Likes

Did you create the API you’re using? If so, on your dynamic data, are you also encapsulating it with " ie:
"<someValue>"? If you are, remove the JSON safe. If it’s not an API you’ve built, I’d be willing to bet that the dynamic values found in the API are in fact "<someValue" and you’d still need to remove JSON safe. in most cases I’ve found json safe to be useless.

:thinking:

1 Like

Thank you so much! This fixed it.

Now I just have to go find all the other places in my app where this might be happening :sweat_smile: