Get request with Array Query works in debugger but not in live

Options

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

Tagged:

Answers

  • arturosanz
    arturosanz Member ✭✭
    Options

    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.

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    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.