I want to send a GET request with URL params specified by some components in retool. The issue that I have is that when the components are empty I don't want the params to appear at all (instead of sending null
.
I tried different things:
- Adding the URL params normally, but this results in the API telling me that
None
is not a valid choice.
- Using an empty string when the field is not selected results in the API telling me that
"
is not a valid value:
- Manually building the URL, saving it in a temporary state and adding that temporary state to the URL results in the
?
being encoded as %3F
:
What are my options here? As soon as I try to move the ?
to the URL retool identifies it as a URL param and adds another =
to the end of the query which makes it fail.
Hey @ktrebing!
You can disable url parameters by passing your conditional to the key
field instead of the value
field. Can you try something like this?
key:
{{ projectFilterSelectBudget.value ? "budget" : null }}
value:
{{ projectFilterSelectBudget.value }}
5 Likes
Ooow, I wouldn't think about that
Clever approach!
1 Like
Hey @Kabirdas , I noticed when the value entry is more complex, this extra query parameter will still be added to the url. eg:
Do you have a solution to my case?
More specifically, I noticed the value being
1/ {{multiselect1.value?international_categories:[${multiselect1.value}]
:null}}
2/ {{international_categories:[${multiselect1.value}]
}}
and
3/ {{multiselect1.value}}
gives me different results for key being null case. where 1/ and 2/ will be nonnull value and the url param still added, and 3/ case not added
the value of an empty multiselect is an empty array which is still truthy, I wonder if that's what you're running into here. Can you try {{ multiselect1.value.length === 0 ? 'filter_by' : null }}
?
1 Like
@Kabirdas
I tried with {{ multiselect1.value.length === 0 ? 'filter_by' : null }}
, the behavior remains the same as my previous description.
Also, I think empty array evaluates to Falsy.
Do you have any other thoughts on possible solution? It feels like a bug on retool RestAPI query
I put the ternary in the wrong order it should be {{ multiselect1.value.length === 0 ? null : 'filter_by' }}
, sorry, can you let me know if that works?
This is a good reference for Truthy/Falsy values! A good alternative to relying on JS type coercion or checking length is to use the built in lodash _.isEmpty
function which is more readable.
It worked! Thank you so much @Kabirdas !!