hotelsCreateOrder method
- String idempotencyKey, {
- HotelOrderRequest? hotelOrderRequest,
- Future<
void> ? abortTrigger,
Book hotels
Places and pays for hotel bookings of up to 5 searched or quoted rates. Requires an Idempotency-Key header (a new UUID per purchase) and an API key with order-manage permission. Repeating the same request with the same key returns the original order; while the first request is still running the response is 202. The order is paid from your wallet balance and each booking completes asynchronously: track it with GET /orders/{id} or the order.fulfillment.updated webhook. The body is { currency, referenceId, items } with 1 to 5 items, each { publicId, quantity, inputs }. publicId is an offer's publicId from search, or the newer one from quote, and quantity must be 1. inputs holds the holder and one roomGuests entry per searched room (roomIndex 1 to N), whose guests must match the searched occupancy and child ages, the optional specialRequests, and the optional price guard maxPrice in the order currency. Unknown fields are rejected with 400. The whole body is validated first: a body error gives 400 / 10001, also when it is in a later item. Once the body is valid, each item is checked completely before the next, and an error names its item in details[].path. Before any money moves each rate is priced again in the order currency and capped: at inputs.maxPrice when sent, else at the price shown with the publicId. Above the cap the order returns 409 / 11002 at items[i].inputs.maxPrice or items[i] (quote again); at or below it the rate is charged as priced, so a maxPrice above the shown price accepts a rise up to it. A rate that cannot be booked now returns 409 / 11003, an offer priced in another currency than the order 400 / 11005, and an unknown, expired or another partner's publicId 400 / 11004, each at items[i]. Offer and hotel-system failures return their hotel codes (21003, 21007–21010) without a path. Nothing is created or charged when the order is refused.
Parameters:
-
String idempotencyKey (required): UUID idempotency key for safe retries of this operation.
-
HotelOrderRequest hotelOrderRequest:
Implementation
Future<HotelOrder?> hotelsCreateOrder(String idempotencyKey, { HotelOrderRequest? hotelOrderRequest, Future<void>? abortTrigger, }) async {
final response = await hotelsCreateOrderWithHttpInfo(idempotencyKey, hotelOrderRequest: hotelOrderRequest, abortTrigger: abortTrigger,);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
// When a remote server returns no body with a status of 204, we shall not decode it.
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
// FormatException when trying to decode an empty string.
if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'HotelOrder',) as HotelOrder;
}
return null;
}