Get API with dynamic queries

Hello, i’ve been struggling with this for a week now so it’s about time to ask for help.

I’ll try to be as descriptive as possible.


  • I have a messages page, that lists many messages i sent. I should be able to filter this list using some inputs and also paginate the data received.
  • The messages come from an API endpoint made by someone else in my company.
  • When fetching the data, i can send a “Current Page” Header!
  • I can also send query parameters related to whatever i need to filter.
  • The response is a JSON Object with:
    • Pagination information (such as total pages or total messages, etc…);
    • The Data list.

Also here is my page (sorry i can’t show you the data, but it’s just the receiver’s name and location).


Now, how could something so simple go wrong?

I’m using the REST API Collection, and issues start when applying the queries, just as i’m doing in this image. I have bound it to my Text Input value, that means when nothing is written on it, it’s value is null, which my API is not a huge fan, so this approach returns 400, and would also require every input to be used, which is not what i want.

  • Creating an Object with the queries? Tried, falls in the same as above.
  • Using the “Filter” option either when fetching or displaying in the list? It’s kind of janking because i can’t control which key i want to target specifically, and it’s pagination also does not suit me.
  • Saving every instance of the API call in an Array and cycling through it? It was great for pagination, but again, i can’t filter.
  • Concatenating a huge string with all the queries and maybe redirecting the page to that? Did as well, try to paginate THIS mess…

Whatever else? I don’t know honestly, this is where i need help.

tl;dr

I need to make an API call to show a list of messages, then update this list with the contents of my input, and be able to paginate this list.

Solved

After trying dozens of ways of doing this, the solution came so simple i can only feel dumb.

Turns out i just had to check if the field was empty in the API call itself. Since it returns “undefined”, the query is not sent as a null value and it all works great.