Find Booking.com hotels in New York for two adults this weekend, without a Booking.com account.
Before you start
You need Node.js 22 or newer and your provisioned connector API URL and bearer token. Set AJAR_API_URL and AJAR_CONNECTOR_TOKEN in your terminal environment. These are connector credentials; a dashboard workspace key alone does not authorize connector calls. Request connector access from ajar if you have not received them. The Booking.com guest runtime must be enabled for your endpoint.
What you’ll send
Start a guest session, predict New York City, then search with the returned place_ref. The example searches a Friday check-in and Sunday check-out for two adults in one room, priced in USD. Dates are calculated each time you run it using New York’s time zone. If it is already Friday or later, it chooses the next Friday so check-in stays in the future. Review the printed dates and change them if you want a different stay.
Run your first search
// Save as first-request.mjs, then run: node first-request.mjs
const base = process.env.AJAR_API_URL?.replace(/\/$/, "");
const token = process.env.AJAR_CONNECTOR_TOKEN;
if (!base || !token) throw new Error("Set AJAR_API_URL and AJAR_CONNECTOR_TOKEN first.");
async function post(path, input, sessionHeaders = {}) {
const response = await fetch(base + path, {
method: "POST",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
...sessionHeaders,
},
body: JSON.stringify(input),
});
const payload = await response.json();
if (!response.ok || payload.ok === false) {
throw new Error("Request failed (HTTP " + response.status + "): " + JSON.stringify(payload));
}
return payload.ok === true ? payload.data : payload;
}
// 1. Start a Booking.com guest session. No Booking.com login needed.
const guest = await post("/v1/connections/booking/guest", {});
const sessionHeaders = guest.connection_ref
? { "x-connection-ref": guest.connection_ref }
: { "x-booking-token": guest.access_token };
if (!guest.connection_ref && !guest.access_token) throw new Error("Guest session was not returned.");
// 2. Resolve New York City. Use the returned reference, never a made-up ID.
const places = await post("/v1/operations/booking.place.predict", { query: "New York" }, sessionHeaders);
const city = places.items.find(place =>
place.country_code === "US" && place.place_type === "city" &&
/new york/i.test(place.name ?? place.display_name ?? "")
);
if (!city) throw new Error("New York City was not found. Inspect the prediction items before continuing.");
// Use the upcoming Friday–Sunday, calculated in New York's time zone.
const today = new Intl.DateTimeFormat("en-CA", {
timeZone: "America/New_York", year: "numeric", month: "2-digit", day: "2-digit",
}).format(new Date());
const checkinDate = new Date(today + "T00:00:00Z");
const daysToFriday = (5 - checkinDate.getUTCDay() + 7) % 7 || 7;
checkinDate.setUTCDate(checkinDate.getUTCDate() + daysToFriday);
const checkoutDate = new Date(checkinDate);
checkoutDate.setUTCDate(checkoutDate.getUTCDate() + 2);
const checkin = checkinDate.toISOString().slice(0, 10);
const checkout = checkoutDate.toISOString().slice(0, 10);
// 3. Find stays for two adults, one room, with prices in USD.
console.log("Searching New York:", checkin, "to", checkout, "— 2 adults, 1 room");
const hotels = await post("/v1/operations/booking.hotel.search", {
place_ref: city.place_ref, checkin, checkout,
adults: 2, rooms: 1, children_ages: [], currency: "USD",
}, sessionHeaders);
console.log(JSON.stringify(hotels, null, 2));Read the response
A successful search returns HTTP 200 and JSON. The items array contains hotel names, photos, review scores, prices and room summaries. The response also echoes the dates, currency and occupancy, and includes search_ref and the available filter catalog. Results and prices are live; an empty items array means no stays were returned for that search. This is a guest search: it does not reserve a room or take a payment.
If a request fails
HTTP 401 or 403: check your connector credential and access permissions. UpstreamDisabled: ask ajar to enable Booking.com guest access. If the guest session or a place/search reference expires, start the script again to create a fresh session and predict the destination again. Place and search references last 15 minutes and are scoped to the same caller and session.