Get request with Array Query works in debugger but not in live
Hi,
Been trying to figure this out for a while now, I have a get request that has an input for an array in the debugger it's passed like this
{ "color_in": ["Red","Green"]}
And when I try to do the same in postman it doesn't work, and I tried all different alternatives but nothing it only works in postman if I try it with just one so like this https://apiendpoint/search2?color_in=Red
https://apiendpoint/search2?color_in=["Red","Green"]
https://apiendpoint/search2?color_in=[Red,Green]
https://apiendpoint/search2?color_in=Red,Green
Any help is much appreciated
Answers
-
Your endpoint is not a GET but probably a POST (or something else). Send the object input in the request body rather than in the URL.
-
Let's assume you make an endpoint with a single input called "color_in" that has a type text and structure list. That will look like text[] in the data type.
To consume it, make an endpoint (here I call it "test-colors" with the following syntax:
https://my-xano-instance/api:abcdefg/test-colors?color_in[]=red&color_in[]=green
You'll get the result you're looking for!That's the what, let me spend a minute on the why:
Xano GET endpoints use PHP-style form syntax to gather arrays. Its a flavor of HTTP form encoding that goes beyond the standard for that syntax (because HTTP form encoding only considers strings on either side of keys and values).JSON is better at typing and knows the difference between numbers, strings, lists, objects, booleans and nulls. You can wrench Xano into using JSON in GET, but it makes things weird, so JSON is a better fit for POST and PUT, as @arturosanz suggests.
We work on the hard parts of setting up APIs every day at State Change in our forums and recorded daily office hours.
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