Is it possible to make query string parameters optional in the API Connector (or API tab of the plugin editor)?
There’s no checkbox to explicitly mark them as optional like there is for headers and body parameters; and if no value is provided, Bubble just sends a valueless parameter, which in the case of this API has specific meaning that is different from not including the parameter at all.
I’ve been tinkering, but I can’t find a way around this. Has anyone had success doing this?
do you have a screenshot?
not sure of your setting so it will help me understand your specific case
You can also check if this plugin can work for you
There’s not a lot of information to know if you can use it for API Connector or it’s just to remove it from current page
Yeah, that’s for the browser address bar - not an API call. Thanks though.
I have something for JSON actually, but not for url parameters.
Did you use setting in Body or only in URL? (is it a GET call or POST?) or in Form DATA with add parameters button?
Query string params 1 and 2 get sent even if there’s no value specified for them in the editor. I was just hoping I was overlooking some way to prevent them from being sent if they have no value - i.e. make them optional. It appears it’s not possible with the API Connector.
Ok. Because you are in a GET request, you don’t have access to body like you have in POST.
I think the best thing would be to create a plugin if you have a lot of possible missing field. If there’s two or three, you could consider using conditionnal to provide correct parameters
instead of putting them in the API connector, you put everything after ? into one [parameters] and in this parameters, you wil lset param1=value1¶m2=value2 (and in editor, you replace the value with dynamic token.) If you have a lot, I think a plugin will be easier to use and create
Can you set up your url in the api connection
Then in your action send the “paramname=“ in or a blank if it’s not needed! Second parameter send in “¶m2name=“
Oi! That just might work! That’s exactly what I needed to get me beyond my mental block! I’ll give it a try.
You can do using regex
Example here with two find and replace
@richard10 gets the gold star!
I’m particularly annoyed with myself given that I already learned this lesson just a week ago!
Of course, that was in the context of the body, and I never even thought to consider that it might apply to the URL itself!
Anyway, thanks much for bringing a fresh perspective to the issue. And thanks, @Jici, for your suggestions as well, but I really wanted to get this to work in the API Connector and/or plugin editor API tab.
This was the same suggestion I had. The only difference is each part separate while I was doing everything after in one
My process was the same setting, just the difference in the action process when you call the API
I only think that with the approach from Richard, is that you probably use conditionnal to set the fields right?
I guess I misunderstood then. My apologies! Either way, I’m happy to have learned something new. Thanks again for taking the time!
Yeah, I think it was your references to a plugin that caused me to miss the relevant part; so thanks much. The API Connector is actually much more flexible than I realized!
In fact, I’ll be passing a list in the query string, so I’ll likely use just a single editor field - i.e. “param” - in conjunction with the new[ish] list
:formatted as text feature.
I think that’ll do it to it.
Yes. And I think after that it would just be possible using asimple regex, no need to use plugin
Another set of eyes clears a lot of mental blocks! Glad to hear it worked!