Last updated

Multi-Destination Bookings with ESIM Optimization

Overview

A single Booking can cover multiple Destinations — just like a travel itinerary spans multiple cities. Pass an array of destination codes in your package_specifications, and Hubby automatically resolves the fewest number of ESIMs required to cover all of them, optimizing both cost and convenience for travelers.

How It Works

  1. Multi-Destination Specification

    • Customers can provide an array of destination countries/regions
    • The system analyzes coverage overlap between destinations
    • ESIMs are selected to minimize the total number required
  2. ESIM Optimization Algorithm

    • The system identifies which ESIMs provide coverage for multiple destinations
    • Regional ESIMs that cover multiple countries are prioritized
    • Individual country ESIMs are used only when necessary
    • The algorithm ensures complete coverage with minimal ESIM count
  3. Coverage Analysis

    • Each ESIM's coverage area is analyzed against the requested destinations
    • Overlapping coverage is identified and utilized
    • The system selects the optimal combination of ESIMs

Benefits

  • Cost Optimization: Fewer ESIMs mean lower total cost
  • Simplified Management: Fewer ESIMs to activate and manage
  • Seamless Travel: Automatic coverage across all destinations
  • Intelligent Routing: System handles complex multi-country itineraries

Use Cases

  • European Tours: Multiple countries in a single trip
  • Business Travel: Conferences and meetings across regions
  • Backpacking: Extended travel through multiple countries
  • Cruise Travel: Multiple port destinations

Technical Implementation

API Endpoints

Hubby provides two API endpoints for different environments:

  • Production: https://api.hubbyesim.com/api - Use this for live applications
  • Staging: https://api-staging.hubby.dev/api - Use this for testing and development

Always test thoroughly in staging before using production.

API Request Structure

When creating a booking with multiple destinations, provide an array of destination specifications:

{
  "departure_date": "2024-06-15",
  "package_specifications": [
    {
      "destination": ["FRA", "DEU", "ITA", "ESP"] // Array of country codes
    }
  ]
}

Response Structure

The response is identical to a typical booking response.

Code Example

Here's a complete example of implementing multi-destination bookings:

import crypto from 'crypto';

// Configuration
const API_SECRET = 'your_api_secret';
const API_KEY = 'your_api_key';
// Use staging for development, production for live
const BASE_URL = process.env.NODE_ENV === 'production' 
  ? 'https://api.hubbyesim.com/api'
  : 'https://api-staging.hubby.dev/api';

// Generate HMAC signature for authentication
function generateSignature(timestamp: string, method: string, path: string): string {
  const payload = `${timestamp}${method}${path}`;
  return crypto
    .createHmac('sha256', API_SECRET)
    .update(payload)
    .digest('hex');
}

// Generate API headers
function generateHeaders(method: string, path: string) {
  const timestamp = Date.now().toString();
  const signature = generateSignature(timestamp, method, path);
  
  return {
    'x-api-key': API_KEY,
    'x-timestamp': timestamp,
    'x-signature': signature,
    'Content-Type': 'application/json'
  };
}

// Create a multi-destination booking
async function createMultiDestinationBooking(
  destinations: string[], 
  departureDate: string, 
  promoCode?: string
) {
  const path = '/api/bookings';
  const method = 'POST';
  
  const requestBody: any = {
    departure_date: departureDate,
    package_specifications: [
      {
        destination: destinations
      }
    ]
  };
  
  if (promoCode) {
    requestBody.promo_code = promoCode;
  }
  
  const response = await fetch(`${BASE_URL}${path}`, {
    method,
    headers: generateHeaders(method, path),
    body: JSON.stringify(requestBody)
  });
  
  return response.json();
}

This feature enables travelers to enjoy seamless connectivity across multiple destinations while minimizing costs and complexity.