API query params optional?

Is there any way to make the API’s query parameters be active only under certain conditions?


This is an action that lists sale offers and there are various parameters I can use to filter the list… However the parameter external.id may not be blank as the list will come out empty (probably because all the offers have some ID there).

I know I could have another action with the same name with a condition set up to use the right action if $_GET.ean is not empty and I would do that if those were the only 2 parameters but sadly there’s a few more I’d like to use

If I’m not being clear enough, I’d like to be able to set it up in a similar way it’s possible query builder:

Hi,
I don’t think there is a way to make that optional.
But, because this is query param, you can just set those params directly in the api url. No need to use the query input grid.

  1. Create a variable with the base url.
  2. Based on condition add your query params to the variable.
  3. Final url variable should look something like https://abc.com?name={{xxx}}&id={{tttt}}
    OR
    https://abc.com?name={{xxx}}
  4. To check, when you output the variable, you should see the final url, with the bindings replaced.
  5. Set this variable as the URL in API action.

Note: variable = set value step.

1 Like

sorry for the slow reply
That’s a great solution! Does exactly what I wanted it to do!
Thanks!

yes, you can use the method Sid says, also unused variables are unimportant. however, you can use conditions in the value field. as follows.

{{parameter == 1 ? parameter1 : parameter2}}

image
you mean the value field here?

the problem is I wanted the whole field to be optional because even if the value is empty the query will return no results (because all records have that id filled)

using sid’s method I can ensure that if id is empty it won’t get passed passed as param