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
const searchResult = await client.hotels.search({
stay: {
checkIn: '2025-06-15',
checkOut: '2025-06-17',
},
destination: {
code: 'BCN',
},
occupancies: [
{
adults: 2,
children: 1,
childrenAges: [8],
},
],
filters: {
currency: 'EUR',
minPrice: 100,
maxPrice: 300,
},
settings: {
accessIds: ['ACCESS_1'],
},
});
console.log(`Found ${searchResult.options.length} options`);
Quote an Option
const quoteResult = await client.hotels.quote({
optionRefId: searchResult.options[0].optionRefId,
settings: {
accessIds: ['ACCESS_1'],
},
});
if (quoteResult.warnings?.some(w => w.code === 'PRICE_CHANGED')) {
console.log('Price has changed:', quoteResult.price);
}
Create a Booking
const booking = await client.hotels.book({
optionRefId: quoteResult.optionQuote.optionRefId,
holder: {
name: 'John',
surname: 'Doe',
email: 'john.doe@example.com',
phone: '+34600123456',
},
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' },
},
clientReference: 'BOOKING-2025-001',
});
console.log('Booking confirmed:', booking.booking.id);
Retrieve Booking
const bookingDetails = await client.hotels.getBooking('BK-987654321');
console.log('Booking status:', bookingDetails.booking.status);
List Bookings
const bookings = await client.hotels.listBookings({
filters: {
status: ['CONFIRMED'],
dateRange: {
from: '2025-06-01',
to: '2025-06-30',
},
},
pagination: {
page: 1,
pageSize: 20,
},
});
console.log(`Found ${bookings.bookings.length} bookings`);
Cancel Booking
const cancelResult = await client.hotels.cancel('BK-987654321', {
reason: 'Customer request',
cancelPenalty: {
apply: true,
},
});
console.log('Cancellation penalty:', cancelResult.booking.cancelInfo?.penalty);
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.search({...});
} 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 = {
stay: {
checkIn: '2025-06-15',
checkOut: '2025-06-17',
},
// 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