关于Booking.com API能否用城市ISO2/ISO3代码替代city_ids调用的问询
city_ids Great question—since Booking.com's core API doesn't support direct ISO 2/3 code calls for city targeting, here are the most reliable ways to work around this:
1. Use the Official Location Autocomplete API
This is the recommended, supported method from Booking.com. The Autocomplete API accepts free-text queries (including ISO 2/3 country codes, city names, or even partial addresses) and returns matching location objects that include the required city_ids.
For example, to get the city_id for Paris using its ISO 2 country code ("FR") combined with the city name, your request might look like this (adjust parameters based on your API credentials):
GET /v1/locations/autocomplete?query=Paris,FR&language=en&api_key=YOUR_API_KEY
In the response, look for objects with the type field set to city—the associated city_id (formatted as -xxxxxx) will be included in the payload. You can filter results to ensure you're grabbing the correct city by cross-referencing with the ISO code in the country object of the response.
2. Build a Local Mapping Database
If you need to make frequent calls for the same set of cities, pre-fetch and store the ISO code ↔ city_id mappings in a local database or JSON file. Here's how to do this:
- Use the Autocomplete API to batch query all your target cities (passing their ISO codes alongside names to ensure accuracy).
- Extract the
city_idfor each valid city result and store the pair (e.g.,{"FR": {"Paris": "-123456"}, "DE": {"Berlin": "-654321"}}). - Periodically refresh this mapping to account for any potential changes to Booking.com's location IDs.
3. Avoid Unofficial Endpoints (Not Recommended)
While some developers have reported finding hidden or undocumented endpoints that might handle ISO code conversions, these are not supported by Booking.com. Relying on them risks sudden breakage if the endpoint is deprecated or modified without notice. Stick to official APIs for long-term stability.
Key Notes
- Ensure your API key has permissions to access the Location Autocomplete API—check your Booking.com developer dashboard if you run into authorization issues.
- When using the Autocomplete API, be specific with your
queryparameter (e.g., combine city name + ISO country code) to avoid ambiguous results (e.g., multiple cities named "London" in different countries).
内容的提问来源于stack exchange,提问作者Ayan Ghosh

