JavaScript & TypeScript SDK
The Bundleport JavaScript/TypeScript SDK provides a type-safe client for the Connect Hotels REST API, making it easy to integrate hotel booking functionality into your Node.js or browser applications.
Install
- npm
- yarn
- pnpm
npm install @bundleport/connect-hotels-sdk
yarn add @bundleport/connect-hotels-sdk
pnpm add @bundleport/connect-hotels-sdk
Initialize the Client
import { BundleportClient } from '@bundleport/connect-hotels-sdk';
const client = new BundleportClient({
apiKey: 'YOUR_API_KEY_HERE',
baseUrl: 'https://api.bundleport.com', // Optional, defaults to production
timeout: 30000, // Optional, request timeout in milliseconds
});
Booking Operations
Search for Hotels (Availability)
const searchResult = await client.hotels.searchAvailability({
criteria: {
checkIn: '2025-06-15T00:00:00Z',
checkOut: '2025-06-17T00:00:00Z',
occupancies: [
{
paxes: [
{ name: 'John', surname: 'Doe', age: 35 },
{ name: 'Jane', surname: 'Doe', age: 33 },
{ name: 'Child', surname: 'Doe', age: 8 },
],
},
],
hotels: ['12345', '67890'], // Optional: specific hotel codes
currency: 'EUR',
language: 'en',
nationality: 'US',
},
settings: {
connectionCodes: ['testb-hbds-1876'],
timeout: 30000,
},
});
console.log(`Found ${searchResult.options.length} options`);
Get Prebooking Quote
const quoteResult = await client.hotels.getPrebooking({
criteria: {
optionRefId: searchResult.options[0].optionRefId,
},
settings: {
connectionCodes: ['testb-hbds-1876'],
},
});
if (quoteResult.warnings?.some(w => w.code === 'PRICE_CHANGED')) {
console.log('Price has changed:', quoteResult.optionQuote.price);
}
Create a Booking
const booking = await client.hotels.createBooking({
input: {
optionRefId: quoteResult.optionQuote.optionRefId,
holder: {
name: 'John',
surname: 'Doe',
title: 'MR',
},
rooms: [
{
occupancyRefId: 1,
paxes: [
{ name: 'John', surname: 'Doe', age: 35 },
{ name: 'Jane', surname: 'Doe', age: 33 },
],
},
],
paymentCard: {
type: 'VI',
number: '4111111111111111',
expire: { month: 12, year: 2027 },
holder: {
name: 'John',
surname: 'Doe',
contactInfo: {
email: 'john.doe@example.com',
phone: { countryCode: '+34', number: '600123456' },
},
},
},
clientReference: 'BOOKING-2025-001',
},
settings: {
connectionCodes: ['testb-hbds-1876'],
},
});
console.log('Booking confirmed:', booking.booking.bookingID);
Retrieve Booking Details
const bookingDetails = await client.hotels.getBookingDetail({
criteria: {
bookingID: 'BK-987654321',
},
settings: {
connectionCodes: ['testb-hbds-1876'],
},
});
console.log('Booking status:', bookingDetails.booking.status);
List Bookings
const bookings = await client.hotels.listBookings({
criteria: {
typeSearch: 'BOOKING_LIST_CRITERIA_TYPE_DATES',
dates: {
dateType: 'BOOKING_LIST_CRITERIA_DATE_TYPE_ARRIVAL',
start: '2025-06-01T00:00:00Z',
end: '2025-06-30T00:00:00Z',
},
// Or search by booking ID:
// typeSearch: 'BOOKING_LIST_CRITERIA_TYPE_BOOKING_ID',
// bookingID: 'BK-987654321',
},
settings: {
connectionCodes: ['testb-hbds-1876'],
},
});
console.log(`Found ${bookings.bookings.length} bookings`);
Cancel Booking
const cancelResult = await client.hotels.cancel({
input: {
bookingID: 'BK-987654321',
},
settings: {
connectionCodes: ['testb-hbds-1876'],
},
});
console.log('Cancellation status:', cancelResult.booking.status);
if (cancelResult.booking.cancelPenalties?.length > 0) {
console.log('Cancellation penalties:', cancelResult.booking.cancelPenalties);
}
Content Operations
Get Hotels
const hotels = await client.content.getHotels({
query: {
destinationCodes: ['BCN'],
maxSize: 100,
},
});
console.log(`Found ${hotels.hotels.hotels.length} hotels`);
Get Rooms
const rooms = await client.content.getRooms({
query: {
connectionCode: 'CONN_1',
maxSize: 50,
},
});
Get Destinations
const destinations = await client.content.getDestinations({
query: {
maxSize: 100,
},
});
Error Handling
try {
const result = await client.hotels.searchAvailability({...});
} catch (error) {
if (error.code === 'UNAUTHORIZED') {
console.error('Invalid API key');
} else if (error.code === 'RATE_LIMIT_EXCEEDED') {
console.error('Rate limit exceeded, retry after:', error.retryAfter);
} else {
console.error('API error:', error.message);
}
}
TypeScript Support
The SDK is written in TypeScript and provides full type definitions:
import type { SearchRequest, SearchResponse } from '@bundleport/connect-hotels-sdk';
const request: SearchRequest = {
criteria: {
checkIn: '2025-06-15T00:00:00Z',
checkOut: '2025-06-17T00:00:00Z',
occupancies: [
{
paxes: [{ name: 'John', surname: 'Doe', age: 35 }],
},
],
},
settings: {
connectionCodes: ['testb-hbds-1876'],
},
// TypeScript will autocomplete and validate all fields
};
Next Steps
- REST API Reference - Complete endpoint documentation
- Content API Reference - Content catalog endpoints
- Error Handling Guide - Learn how to handle errors