amadeus4dev / amadeus-node

Node library for the Amadeus Self-Service travel APIs
https://developers.amadeus.com
MIT License
191 stars 66 forks source link

Can't pass arrays as parameters to hotels.byCity.get endpoint: it results in a 400 response #220

Open gianpieropuleo opened 2 months ago

gianpieropuleo commented 2 months ago

Description

The amadeus.referenceData.locations.hotels.byCity.get endpoint seems to not support passing arrays as parameters

Steps to Reproduce

const getHotelsByCity = async ({
  cityCode,
  radius = 5,
  radiusUnit = "KM",
  chainCodes = [],
  amenities = [],
  ratings = [],
  hotelSource = "ALL",
}) => {
 const result = await amadeus.referenceData.locations.hotels.byCity
    .get({
      cityCode,
      radius,
      radiusUnit,
      chainCodes,
      amenities,
      ratings,
      hotelSource,
    })
    .catch((error) => {
      console.error(error);
    });

  return result;
};

Expected Behavior:

I would have expected to be able to pass arrays, give we're working with Node. Plus the documentation says those parameters (chainCodes, amenities and ratings) are arrays of strings.

Actual Behavior:

When passing an array to any of those parameters, the response is 400, Invalid Format. This seems to be caused by how array get represented in the GET request:

'v1/reference-data/locations/hotels/by-city?cityCode=MIL&radius=5&radiusUnit=KM&hotelSource=ALL&amenities%5B0%5D=FITNESS_CENTER&ratings%5B0%5D=4&ratings%5B1%5D=5'

In order for it to work, I need to convert them to comma separated values. The documentation for ratings gave a hint on that:

chainCodes.join(",");

Maybe this is expected behavior, but in that case perhaps it should be documented and/or added in the code example.

Stable Behavior?

100% of the times.

Versions

Running Node version 20.17.0 on MacOS Sonoma 14.6.1

Checklist

Please make sure you checked the following: