skip to Main Content

I was getting error as Internal Server Error (500)
when I use flight search API with correct parameters. If any thing wrong in my code can anyone explain me.

{ "errors": [ { "code": 38189, "title": "Internal error", "detail": "An internal error occurred, please contact your administrator", "status": 500 } ] }

I tried to do flight search API integration in my project and I want to know there is any problem from server side or from me.

const handleSubmit = async (e) => {
    e.preventDefault();
    try {
      const fromIATA = formData.from_inp.split('(')[1].replace(')', '');
      const toIATA = formData.to_inp.split('(')[1].replace(')', '');

      const params = {
        originLocationCode: fromIATA,
        destinationLocationCode: toIATA,
        departureDate: formData.depart_inp,
        adults: 1, // Assuming default value for adults
        children: 1 // Adjust for child passengers
      };

      // Conditionally add the returnDate if provided
      if (formData.return_inp) {
        params.returnDate = formData.return_inp;
      }

      // Fetch access token
      const tokenResponse = await axios.post('https://test.api.amadeus.com/v1/security/oauth2/token', {
        grant_type: 'client_credentials',
        client_id: 'fAAnCC012DHFdZXasXhJDmArGCxy9AUG',
        client_secret: 'g37ICvXMDNjSChef'
      }, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      });

      const accessToken = tokenResponse.data.access_token;

      // Fetch flight offers
      const response = await axios.get('https://test.api.amadeus.com/v2/shopping/flight-offers', {
        params: params,
        headers: {
          'Authorization': `Bearer ${accessToken}`
        }
      });

      const apiResponse = response.data;

      console.log('API Response:', apiResponse);

      if (Array.isArray(apiResponse.data)) {
        setFlightDetails(apiResponse.data);
        setError(''); // Clear any previous errors
      } else {
        setError('No flight details match your search.');
        setFlightDetails([]); // Clear previous flight details
      }
    } catch (error) {
      console.error('Error fetching flight offers:', error);
      setError(`Error fetching flight details: ${error.message}`);
      setFlightDetails([]); // Clear previous flight details
    }
  };

2

Answers


  1. This error indicates that something went wrong on the server side, but it doesn’t provide specific details about what caused the issue.
    Here is some things you should to do:

    • If possible, review the full response body or headers for any additional information that might be useful in diagnosing the issue.
    • Try making requests with different parameters or minimal parameters to see if the issue persists. This can help determine if specific parameters are causing the problem.

    Otherwise it’s hard to solve 🙂

    Login or Signup to reply.
  2. I’m getting exactly the same error when I use code that worked before. In fact Amadeus’ own example webpages produce the same error when in the past they used to work for me.

    https://developers.amadeus.com/self-service/category/flights/api-doc/flight-offers-search/api-reference

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search