Bắt đầu nhanh
Trên trang này, bạn sẽ lấy token bằng thông tin xác thực đối tác và gửi một truy vấn phòng và giá. Bạn cần apiKey, apiSecret và ID HMS của khách sạn (hotelID); nếu chưa có, hãy liên hệ bộ phận hỗ trợ.
1. Lấy token#
Endpoint đăng nhập nhận trường form và không cần header xác thực:
curl "https://test.hms.gen.tr/external/public/login" \
-d "apiKey=$HMS_API_KEY" \
-d "apiSecret=$HMS_API_SECRET" \
-d "hotelCode=1000"{
"success": true,
"hotelCode": "1000",
"token": "eyJlbmREYXRlIjp7ImRhdGUiOiIyMDI2LTA5LTE1IDEwOjI0OjMxLjAwMDAwMCIs…",
"hotelSeoUrl": "demo-otel"
}Hãy lưu token; token này được dùng trong mọi yêu cầu cho khách sạn này trong 7 ngày.
export HMS_TOKEN="eyJlbmREYXRlIjp7ImRhdGUiOiIyMDI2LTA5LTE1IDEwOjI0OjMxLjAwMDAwMCIs…"2. Truy vấn phòng và giá#
Tìm kiếm hai đêm cho hai người lớn:
curl "https://test.hms.gen.tr/external/online/roomType" \
-H "Authorization: Bearer $HMS_TOKEN" \
-d "hotelID=1000" \
-d "startDate=2026-08-18" \
-d "endDate=2026-08-20" \
-d "adultCount=2" \
-d "language=en"const res = await fetch("https://test.hms.gen.tr/external/online/roomType", {
method: "POST",
headers: { "Authorization": `Bearer ${process.env.HMS_TOKEN}` },
body: new URLSearchParams({
hotelID: "1000",
startDate: "2026-08-18",
endDate: "2026-08-20",
adultCount: "2",
language: "en"
})
});
const data = await res.json();
if (!data.success) throw new Error(`${data.errorCode}: ${data.errorMessage}`);
for (const room of data.items) {
console.log(room.name, room.roomCount, "rooms");
}$ch = curl_init('https://test.hms.gen.tr/external/online/roomType');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('HMS_TOKEN')],
CURLOPT_POSTFIELDS => http_build_query([
'hotelID' => 1000,
'startDate' => '2026-08-18',
'endDate' => '2026-08-20',
'adultCount' => 2,
'language' => 'en',
]),
]);
$data = json_decode(curl_exec($ch), true);
if (empty($data['success'])) {
throw new RuntimeException($data['errorCode'] . ': ' . $data['errorMessage']);
}
foreach ($data['items'] as $room) {
echo $room['name'], ' · ', $room['roomCount'], " rooms\n";
}3. Đọc phản hồi#
Mỗi loại phòng chứa các gói ăn của nó (accommodationTypes), và mỗi gói ăn chứa các lựa chọn giá (prices). Ví dụ rút gọn:
{
"success": true,
"items": [
{
"id": 2,
"name": "Standard Room",
"roomCount": 5,
"currency": "TRY",
"accommodationTypes": [
{
"id": 2,
"title": "Bed & Breakfast",
"priceType": 0,
"prices": {
"2-1": {
"total": 2,
"price": "1930.00",
"currency": "TRY",
"nonRefundable": "",
"id": "2/2"
},
"2-0": {
"total": 2,
"price": "1737.00",
"currency": "TRY",
"nonRefundable": "[NR]",
"id": "2-0/2"
}
}
}
]
}
],
"count": 1
}2-1: 2 người, giá tiêu chuẩn (được hoàn tiền).2-0: 2 người, giá không hoàn tiền (nonRefundable: "[NR]").pricelà tổng tiền cho cả kỳ lưu trú;totallà số đêm. Giá theo từng đêm nằm trong mảngprices[]của phản hồi đầy đủ.- Khi đặt phòng,
idcủa loại phòng được gửi dưới dạngroomTypeIDvàidcủa gói ăn dưới dạngratePlanID.
Tiếp theo#
- Luồng đặt phòng — từ lúc chọn phòng đến khi gửi
BookingPushRQ - Luồng thanh toán — thanh toán tại khách sạn, chuyển khoản ngân hàng, thẻ tín dụng, thanh toán trực tuyến
- Mã lỗi — các giá trị
errorCodevàmessage