@switchfly/core-search-url
v1.2.0
Published
Build Switchfly shopping deep-link URLs from search parameters
Maintainers
Readme
@switchfly/core-search-url
Build Switchfly shopping deep-link URLs from search parameters.
Getting location tokens
Location tokens (e.g. |city:7321, |airport:LAX, |hotel:abc123) are required for the location and fromLocation parameters. They are returned by the Switchfly locations autocomplete API:
GET /apps/api/locations/?locationType=DESTINATION&productTypes=ROOM&searchQuery=san+diegoEach result includes a search field — that value is the token to pass to buildUrl. You can query this API directly or use the @switchfly/sdk locations client if available.
Install
npm install @switchfly/core-search-urlUsage
import { buildUrl } from '@switchfly/core-search-url';
const url = buildUrl(
{
type: 'HOTEL',
location: '|city:7321',
fromDate: '06/01/2026',
toDate: '06/05/2026',
numAdults: 2,
},
{
targetUrl: 'https://arrivals.switchfly.com',
cobrand: 'aav',
}
);
console.log(url.toString());
// https://arrivals.switchfly.com/shopping/search/?clear=true&room1=true&...API
buildUrl(searchInfo, config)
Returns a URL object representing the deep link.
searchInfo
| Parameter | Type | Required | Description |
|---|---|---|---|
| type | 'HOTEL' \| 'AIR' \| 'CAR' \| 'ACTIVITY' \| 'BUNDLE' | ✅ | Product type |
| bundleTypes | string[] | BUNDLE only | e.g. ['AIR', 'HOTEL'] |
| location | string | ✅ | Destination token (e.g. '\|city:7321', '\|airport:LAX') |
| fromLocation | string | AIR / CAR | Origin token |
| fromDate | Date \| string | ✅ | Check-in / departure (MM/DD/YYYY or Date) |
| toDate | Date \| string | | Check-out / return |
| numAdults | number | | Adults (default: 2) |
| childAges | number[] | | Child ages. For AIR: 0 = infant in seat, 1 = infant in lap |
| rooms | object[] | | Per-room traveler config for multi-room hotel searches |
| roundtrip | boolean | AIR | true = roundtrip, false = one-way |
| serviceClass | string | AIR | e.g. 'coach', 'business' (default: 'coach') |
| airline | string | AIR | Airline code filter |
| directOnly | boolean | AIR | Nonstop flights only |
| fromTime | number | CAR | Pickup hour 0–23 (default: 12) |
| toTime | number | CAR | Dropoff hour 0–23 (default: 12) |
| driverAge | number | CAR | Driver age |
| driverAgeDefault | boolean | CAR | Use platform default driver age |
| numRooms | number | HOTEL | Number of rooms |
| switchflyId | string | | Hotel or activity ID — triggers redirect to details page |
| crsName | string | ACTIVITY | CRS name (required with switchflyId for activities) |
| activities | object[] | ACTIVITY | [{ activityId, crsName }] for multi-activity |
| partialRoomStay | boolean | BUNDLE | Enable partial hotel stay |
| partialCheckIn | Date \| string | BUNDLE | Partial stay check-in |
| partialCheckOut | Date \| string | BUNDLE | Partial stay check-out |
config
| Parameter | Type | Description |
|---|---|---|
| targetUrl | string | Base URL of the Switchfly booking platform ✅ |
| cobrand | string | Cobrand identifier (appended as nav=) |
| originUrl | string | Referring page URL (for analytics) |
| discountCode | string | Discount / promo code |
| currency | string | 3-letter ISO currency code (e.g. 'USD') |
| languageId | number | Language ID |
| utmSource | string | UTM source |
| utmMedium | string | UTM medium |
| utmCampaign | string | UTM campaign |
| utmContent | string | UTM content |
| trackId | number | Track ID |
| hotel_id | string | Hotel ID override |
| redirect_to_hotel_details | boolean | Redirect to hotel details page |
| activity_id | string | Activity ID override |
| activity_crs | string | Activity CRS name |
| redirect_to_activity_details | boolean | Redirect to activity details page |
Examples
Hotel search
buildUrl(
{ type: 'HOTEL', location: '|city:7321', fromDate: '06/01/2026', toDate: '06/05/2026' },
{ targetUrl: 'https://arrivals.switchfly.com', cobrand: 'aav' }
);Round-trip flight
buildUrl(
{
type: 'AIR',
location: '|airport:JFK',
fromLocation: '|airport:LAX',
fromDate: '06/01/2026',
toDate: '06/08/2026',
roundtrip: true,
serviceClass: 'business',
},
{ targetUrl: 'https://arrivals.switchfly.com' }
);Air + Hotel bundle
buildUrl(
{
type: 'BUNDLE',
bundleTypes: ['AIR', 'HOTEL'],
location: '|city:7321',
fromLocation: '|airport:LAX',
fromDate: '06/01/2026',
toDate: '06/08/2026',
roundtrip: true,
},
{ targetUrl: 'https://arrivals.switchfly.com', cobrand: 'aav' }
);Featured hotel (redirect to details)
buildUrl(
{ type: 'HOTEL', location: '|city:7321', fromDate: '06/01/2026', toDate: '06/05/2026', switchflyId: 'abc123' },
{ targetUrl: 'https://arrivals.switchfly.com' }
);License
UNLICENSED — internal Switchfly use.
