Skip to main content

Go SDK

The Bundleport Go SDK provides a type-safe client for the Connect Hotels REST API.

Install

go get github.com/bundleport/connect-hotels-sdk

Initialize the Client

package main

import (
"context"
"time"

"github.com/bundleport/connect-hotels-sdk"
)

func main() {
client := bundleport.NewClient(
bundleport.WithAPIKey("YOUR_API_KEY_HERE"),
bundleport.WithBaseURL("https://api.bundleport.com"), // Optional
bundleport.WithTimeout(30*time.Second), // Optional
)

// Use the client...
}

Booking Operations

Search for Hotels (Availability)

ctx := context.Background()

searchResult, err := client.Hotels.SearchAvailability(ctx, bundleport.SearchRequest{
Criteria: &bundleport.SearchCriteria{
CheckIn: "2025-06-15T00:00:00Z",
CheckOut: "2025-06-17T00:00:00Z",
Occupancies: []bundleport.Occupancy{
{
Paxes: []bundleport.Pax{
{Name: "John", Surname: "Doe", Age: 35},
{Name: "Jane", Surname: "Doe", Age: 33},
{Name: "Child", Surname: "Doe", Age: 8},
},
},
},
Hotels: []string{"12345", "67890"}, // Optional
Currency: "EUR",
Language: "en",
Nationality: "US",
},
Settings: &bundleport.Settings{
ConnectionCodes: []string{"testb-hbds-1876"},
Timeout: 30000,
},
})
if err != nil {
log.Fatal(err)
}

fmt.Printf("Found %d options\n", len(searchResult.Options))

Get Prebooking Quote

quoteResult, err := client.Hotels.GetPrebooking(ctx, bundleport.QuoteRequest{
Criteria: &bundleport.QuoteCriteria{
OptionRefId: searchResult.Options[0].OptionRefId,
},
Settings: &bundleport.Settings{
ConnectionCodes: []string{"testb-hbds-1876"},
},
})
if err != nil {
log.Fatal(err)
}

// Check for price changes
for _, warning := range quoteResult.Warnings {
if warning.Code == "PRICE_CHANGED" {
fmt.Println("Price has changed:", quoteResult.OptionQuote.Price)
}
}

Create a Booking

booking, err := client.Hotels.CreateBooking(ctx, bundleport.BookRequest{
Input: &bundleport.BookInput{
OptionRefId: quoteResult.OptionQuote.OptionRefId,
Holder: bundleport.Holder{
Name: "John",
Surname: "Doe",
Title: "MR",
},
Rooms: []bundleport.BookRoom{
{
OccupancyRefId: 1,
Paxes: []bundleport.Pax{
{Name: "John", Surname: "Doe", Age: 35},
{Name: "Jane", Surname: "Doe", Age: 33},
},
},
},
PaymentCard: &bundleport.PaymentCard{
Type: "VI",
Number: "4111111111111111",
Expire: bundleport.CardExpire{Month: 12, Year: 2027},
Holder: bundleport.CardHolder{
Name: "John",
Surname: "Doe",
ContactInfo: bundleport.ContactInfo{
Email: "john.doe@example.com",
Phone: bundleport.Phone{
CountryCode: "+34",
Number: "600123456",
},
},
},
},
ClientReference: "BOOKING-2025-001",
},
Settings: &bundleport.Settings{
ConnectionCodes: []string{"testb-hbds-1876"},
},
})
if err != nil {
log.Fatal(err)
}

fmt.Printf("Booking confirmed: %s\n", booking.Booking.BookingID)

Retrieve Booking Details

bookingDetails, err := client.Hotels.GetBookingDetail(ctx, bundleport.BookingDetailRequest{
Criteria: &bundleport.BookingDetailCriteria{
BookingID: "BK-987654321",
},
Settings: &bundleport.Settings{
ConnectionCodes: []string{"testb-hbds-1876"},
},
})
if err != nil {
log.Fatal(err)
}

fmt.Printf("Booking status: %s\n", bookingDetails.Booking.Status)

List Bookings

bookings, err := client.Hotels.ListBookings(ctx, bundleport.BookingListRequest{
Criteria: &bundleport.BookingListCriteria{
TypeSearch: "BOOKING_LIST_CRITERIA_TYPE_DATES",
Dates: &bundleport.BookingListDates{
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: &bundleport.Settings{
ConnectionCodes: []string{"testb-hbds-1876"},
},
})
if err != nil {
log.Fatal(err)
}

fmt.Printf("Found %d bookings\n", len(bookings.Bookings))

Cancel Booking

cancelResult, err := client.Hotels.Cancel(ctx, bundleport.CancelRequest{
Input: &bundleport.CancelInput{
BookingID: "BK-987654321",
},
Settings: &bundleport.Settings{
ConnectionCodes: []string{"testb-hbds-1876"},
},
})
if err != nil {
log.Fatal(err)
}

fmt.Printf("Cancellation status: %s\n", cancelResult.Cancel.Status)
if len(cancelResult.Cancel.CancelPenalties) > 0 {
for _, penalty := range cancelResult.Cancel.CancelPenalties {
fmt.Printf("Cancellation penalty: %.2f %s\n", penalty.Value, penalty.Currency)
}
}

Content Operations

Get Hotels

hotels, err := client.Content.GetHotels(ctx, bundleport.HotelsRequest{
Query: &bundleport.HotelListQuery{
DestinationCodes: []string{"BCN"},
MaxSize: 100,
},
})
if err != nil {
log.Fatal(err)
}

fmt.Printf("Found %d hotels\n", len(hotels.Hotels.Hotels))

Error Handling

import "github.com/bundleport/connect-hotels-sdk/errors"

result, err := client.Hotels.SearchAvailability(ctx, request)
if err != nil {
var apiErr *errors.APIError
if errors.As(err, &apiErr) {
switch apiErr.Code {
case "UNAUTHORIZED":
log.Fatal("Invalid API key")
case "RATE_LIMIT_EXCEEDED":
log.Printf("Rate limit exceeded, retry after: %d seconds", apiErr.RetryAfter)
default:
log.Printf("API error: %s", apiErr.Message)
}
} else {
log.Fatal(err)
}
}

Next Steps