Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
How can I create a fetch url with optional input fields within a web application

I am making an API call by using fetch method(GET) of Jquery. My question is, how can include empty input fields (totally optional, user may fill those areas, maybe not) into my fetch url. When I tried to send them as empty string, server is responding with a status code(400)- bad request.

These are the optional input fields to fill enter image description here

MY JAVASCRIPT CODE

var fetchUrl = "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode="
+iataOrigin+"&destinationLocationCode="
+iataDestination+"&departureDate="
+getFlightDepartureDate()+"&adults="
+getFlightAdults()+"&max="+getmaxTicket()

console.log(fetchUrl)

const settings = {
    "url": fetchUrl,
    "method": "GET",
    "headers": {
        
            "Authorization" : "Bearer myTokenInHere"

    }
};

$.ajax(settings).done(function (response) {
    console.log(response);
});

For instance, I want to declare a URL such as 'adult number input field value' is not initialized, it's an empty string. Like this :

"&adults="

After trying this, server is not responding with a status code 200. I would be very thankful for your help.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!