How do I handle optional query parameter?

  • Dan

    6 months ago

    I have a button that populates a query parameter only on click. I have a variable with default value null that gets specific value "A" when the button is clicked which will be used as a query parameter in the API request.

    How do I make this query parameter optional so that when the button is not clicked this parameter is omitted in the request URL?
  • Erik Beuschau

    6 months ago

    Optional query parameters in API requests are coming with the new version of APIs (that we're currently working on).
    For now, you will need to have 2 different API requests and call the relevant one depending on the state of your application.
    πŸ‘2
  • Fisher

    4 months ago

    @Erik Beuschau Do you have a timeline for the new version of APIs? Additionally, how would you suggest going about putting together a marketplace-type search? An example would be an auto marketplace, where the price, make, model, year, mileage etc are all optional in the API query? Are you saying we'd need 10's of different API calls depending on what's been selected/filtered by the user?
  • Erik Beuschau

    4 months ago

    Timelines often change πŸ˜‰ But we are testing internally atm, and hope to start testing with heroes in a week or two. Depending on feedback, we will roll them out for everyone shortly after 🀞
    If you have a lot of different (optional) filters, I think the better option for now is to not use query parameters in the API dialog, and just embed them directly in the url using a formula. In that formula, you can handle the optional logic and only include the filters needed
    πŸ‘1
  • Fisher

    4 months ago

    Thanks, Erik. That's totally understandable on timelines!
    I watched a couple videos (one of yours, I think!) on adding querys to a url with formulas, but I'm not sure how to get that to actually filter the info on the page. Does the API grab all records and then the url query filters it down? Or does the url query somehow get passed to the API?
  • Erik Beuschau

    4 months ago

    Query parameters are sent with an https request to your server/back-end that will need to use the passed information to filter the results for the client.
  • Fisher

    4 months ago

    I think I'm understanding now, thanks. I'll need to brush up on formulas, but I appreciate the direction/suggestion!
    πŸ™Œ1
  • /attachments/1259669930178121860/1281259223698640997/image.png

    Fisher

    4 months ago

    I've got it working now, thank you again! For posterity, my issue was that I was still trying to construct the formula within the Query and Path formulas (red arrows), instead of building the whole thing in the API URL formula (green arrow).
    image.png
    πŸ”₯1

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code β€” but accessible to your entire team!

Try toddle β€” it's free!

Β© Copyright 2024 toddle. All rights reserved.