Skip to content

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

@gianpieropuleo

Description

@gianpieropuleo

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:

  • Are you running any of the current Node LTS versions? Yes
  • Did you download the latest version of this library? Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions