Show all records if URL param is empty?
![James Cowen](https://us.v-cdn.net/6037124/user_avatars/4497106.jpg)
Hi Everyone
I'm doing a fetch GET request to my API endpoint.
I have an external filter setup for members location, which is sent to the API as a URL param.
"URL_ENDPOINT?location=27" and this works. Shows results for location 27.
I have set this up following the Xano docs on External Filtering. My input "location" is of type integer (the id from the locations table).
But how can I return all locations if a user selects nothing in the frontend?
This should be the default value too on page load.
I've tried null or nothing and they don't work.
"?location=null" = ("Value \"null\" is not a valid integer.")
"?location=" [] (empty array)
TIA
~James
Comments
-
You need to create a variable at the start of your function stack with a condition:
- If input location is "null" or isEmpty, then var location = null
- else var location = input location
Then, in query all, check the "ignore empty values" box and use the variable location instead of input location
-
Hey @Geoffroy-CYD
Thanks for the reply and suggestion. I've followed your suggestion and no matter what I try I keep getting the error:
{
code: ERROR_CODE_INPUT_ERROR,
message: Value "null" is not a valid integer.,
param: location
}
This is my function stack (see below screenshot)
I run and debug the following as I'm trying to test the string of null
{ "location": "null"} - error
{ "location": ""} - empty string works and returns all locations
Just cannot convert "null" into null.
Am I missing something? -
@James Cowen You have to allow null value for your input and/or delete input in url ({location})
-
you have to use is_empty filter instead of location == NA in your condition
-
@Geoffroy-CYD sorry I don't understand, can you show a screengrab perhaps?
Do you mean make the location input nullable set to yes?
is_empty filter makes the type a bool but it still wants an integer?
If you could show me how to set this up in pictures or video I'd really appreciate it.cheers
-
@James Cowen
You can't use location input as url param if you want allow null value"Do you mean make the location input nullable set to yes?"
Exactly !About is_empty filter :
-
@Geoffroy-CYD very confusing but I think I got it working with some changes to my frontend JS.
thanks kindly for your help.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback