在您自己的網站或應用程式中顯示可預約時段,透過 API 預約、改期或取消,並封鎖時段和管理候補名單,由 Book-and-Pay 為您發送 WhatsApp 確認與提醒。
在本指南中,您自己的網站或應用程式透過 app2email 的 Book-and-Pay 和行事曆 API 接受預約。您的頁面顯示服務和可預約時段,客戶挑選其中一個,您的伺服器用一次呼叫完成預約。
客戶看到的內容: 他們在您的網站上選擇 9:00 的剪髮,並輸入姓名和 WhatsApp 號碼。幾秒後,來自您企業的 WhatsApp 訊息送達:「You're booked: Haircut on ... at 9:00 AM (30 min). Reference BK-7Q3M2A. Reply CANCEL if your plans change.」,並附有可加入手機行事曆的行事曆檔案。看診前會收到附有 Confirm、Reschedule 和 Cancel 按鈕的提醒。
您看到的內容: 預約會出現在您連接的行事曆中(Google、Microsoft 365、Apple iCloud,或 app2email 自己的行事曆應用程式),每筆新預約都會收到一封電子郵件,而每一筆預約、改期、取消和候補提供,無論預約是在哪裡建立的,都會有 webhook 事件。
您不需要自己發送任何 WhatsApp 訊息。Book-and-Pay 會撰寫確認、提醒、「已改期」和「已取消」通知,並在客戶的 24 小時視窗已關閉時,挑選已核准的範本。
GET /bookings/services)和可預約時段(GET /bookings/availability 或 GET /bookings/next)。POST /bookings/holds)。POST /bookings)。Book-and-Pay 會寫入行事曆事件、發送 WhatsApp 確認、寄電子郵件給您,並向您的 webhook 發送 booking.created。POST /bookings/{id}/reschedule)、變更詳細資料(PATCH /bookings/{id}),或取消(POST /bookings/{id}/cancel)。每次都會透過 WhatsApp 通知客戶。POST /calendar/blocks),並把客戶放進已客滿日期的候補名單(POST /bookings/waitlist)。當時段空出來時,Book-and-Pay 會透過 WhatsApp 向他們提供該時段。每次呼叫都發送到 https://api.app2email.com/v1/YOUR_NUMBER,並帶上 Authorization: Bearer YOUR_API_KEY。YOUR_NUMBER 是您的 WhatsApp 號碼:國碼在前,只用數字。
booking_not_enabled。plan_not_allowed;服務暫停時會回應 403 service_not_live。請參閱入門指南。| 權限範圍 | 為何需要 |
|---|---|
bookings:manage | 預約、保留、改期、變更和取消預約,封鎖時段,候補名單。它也涵蓋所有預約的讀取 |
messages:read | 對只讀取的金鑰來說,單靠它就夠了:服務、可預約時段、預約、行事曆、候補名單 |
webhooks:manage | 註冊一次 webhook(POST /webhooks)。您也可以在 API 金鑰頁面的 Webhooks 下新增,不需要寫程式 |
預設金鑰(在金鑰有權限設定之前建立的)沒有 bookings:manage。請建立具備該權限範圍的金鑰,或具備完整存取權(*)的金鑰。GET /v1/YOUR_NUMBER/me 會顯示您目前金鑰的權限範圍。
先試用看看。 即時沙盒(示範號碼 12025550100)沒有預約相關呼叫:它們會回應 403 not_in_instant_sandbox。在您自己號碼上的沙盒金鑰(在 API 金鑰頁面建立、帶有沙盒標記的金鑰)可以讀取您真實的服務、可預約時段、預約、行事曆和候補名單,所以您可以用它建立整個「選擇時間」的部分。每個會變更資料的呼叫(預約、保留、改期、取消、封鎖、候補名單),用它都會回應 403 sandbox_key。若要試用真正的預約,請使用一般金鑰,並以您自己的電話號碼作為客戶,然後再把預約取消。詳情:沙盒。
GET /bookings/services(權限範圍 bookings:manage 或 messages:read)會給您客戶可以預約的服務,包含時長、價格、說明,以及負責每項服務的工作人員。id 會用在其他每個呼叫中。
curl https://api.app2email.com/v1/YOUR_NUMBER/bookings/services \
-H "Authorization: Bearer YOUR_API_KEY"const API = `https://api.app2email.com/v1/${process.env.NUMBER}`;
const headers = { Authorization: `Bearer ${process.env.API_KEY}` };
const res = await fetch(`${API}/bookings/services`, { headers });
const { services, timezone } = await res.json();
console.log(timezone, services);import os, requests
API = f"https://api.app2email.com/v1/{os.environ['NUMBER']}"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}"}
res = requests.get(f"{API}/bookings/services", headers=HEADERS, timeout=10)
print(res.json())您會收到的回應:
{
"success": true,
"request_id": "c6sv7",
"services": [
{ "id": "haircut", "name": "Haircut", "duration_min": 30, "price": "$40", "description": null, "staff": ["maria", "tom"] }
],
"timezone": "Australia/Sydney",
"enabled": true
}企業沒有工作人員時,staff 為空。GET /bookings/staff 會列出工作人員(在其他呼叫中稱為 provider_id)以及他們各自負責的服務。enabled 必須是 true:表示 Book-and-Pay 已開啟。
GET /bookings/availability(權限範圍 bookings:manage 或 messages:read)會給您某個範圍內每一天的可預約開始時間,就像客戶會看到的一樣:營業時間、休息日、已預約的預約、已封鎖的時段,以及您連接的行事曆中的忙碌時間,都已經套用。
| 查詢參數 | 要填寫什麼 |
|---|---|
service_id | 步驟 1 中的服務 |
from, to | 第一天和最後一天,格式為 YYYY-MM-DD,使用企業所在時區。預設:今天起共 7 天;最多 32 天 |
provider_id | 某位工作人員自己的時段。省略時:任何有空的人 |
addons | 以逗號分隔的服務加購項目 id:只顯示足夠長、能容納它們的時段 |
seats | 團體服務時:需要的名額(1 + 同行人數) |
curl "https://api.app2email.com/v1/YOUR_NUMBER/bookings/availability?service_id=haircut&from=2026-11-10&to=2026-11-11" \
-H "Authorization: Bearer YOUR_API_KEY"const q = new URLSearchParams({ service_id: "haircut", from: "2026-11-10", to: "2026-11-11" });
const res = await fetch(`${API}/bookings/availability?${q}`, { headers });
const { days } = await res.json();
for (const day of days) console.log(day.date, day.slots.map((s) => s.title));res = requests.get(f"{API}/bookings/availability", headers=HEADERS, timeout=10,
params={"service_id": "haircut", "from": "2026-11-10", "to": "2026-11-11"})
for day in res.json()["days"]:
print(day["date"], [s["title"] for s in day["slots"]])您會收到的回應:
{
"success": true,
"request_id": "a9xw1",
"timezone": "Australia/Sydney",
"enabled": true,
"days": [
{
"date": "2026-11-10",
"slots": [
{ "id": "2026-11-10T09:00", "title": "9:00 AM", "start": "2026-11-09T22:00:00.000Z", "end": "2026-11-09T22:30:00.000Z", "providers": ["maria", "tom"] },
{ "id": "2026-11-10T09:30", "title": "9:30 AM", "start": "2026-11-09T22:30:00.000Z", "end": "2026-11-09T23:00:00.000Z", "providers": ["tom"] }
]
},
{ "date": "2026-11-11", "slots": [] }
]
}title 顯示給客戶,並保留時段的 id:它是企業所在時區的當地時間(yyyy-MM-ddTHH:mm),下一個呼叫會把它當作 start。start 和 end 是同一時間的 UTC 表示。providers 列出在該時段有空的工作人員。slots 清單為空的日子表示已客滿或休息。已客滿的日子正是候補名單能派上用場的地方。只需要「接下來的空檔」? GET /bookings/next?service_id=haircut&count=3 會給您跨日期的接下來可預約開始時間(最多往後 60 天),適合用於「Next free: tomorrow 9:00」這類按鈕:
{
"success": true,
"request_id": "c8nx9",
"slots": [
{ "id": "2026-11-12T09:00", "date": "2026-11-12", "title": "9:00 AM", "start": "2026-11-11T22:00:00.000Z", "end": "2026-11-11T22:30:00.000Z", "providers": ["maria"] }
],
"count": 1,
"timezone": "Australia/Sydney",
"enabled": true
}這是選用步驟,但可以讓客戶不會遇到「抱歉,那個時段已經沒了」。POST /bookings/holds(權限範圍 bookings:manage)會把一個可預約時段保留 minutes 分鐘(1 到 30,預設 10)。在保留期間,它在所有地方都視為已被占用:在可預約時段、行事曆和每一次預約檢查中,在 WhatsApp 上預約的客戶也一樣。
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/holds \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: hold-session-8f2c1a" \
-d '{"service_id": "haircut", "start": "2026-11-10T09:00", "provider_id": "maria", "minutes": 10}'您會收到的回應(201 Created):
{
"success": true,
"request_id": "f1hc2",
"hold": {
"reference": "BK-7Q3M2A",
"status": "held",
"service_id": "haircut",
"provider_id": "maria",
"contact": "",
"name": "",
"start": "2026-11-09T22:00:00.000Z",
"end": "2026-11-09T22:30:00.000Z",
"start_local": "2026-11-10T09:00",
"end_local": "2026-11-10T09:30",
"expires": "2026-11-09T04:10:00.000Z",
"source": "api"
},
"note": "The time is kept until hold.expires: nobody else can book it."
}請向客戶顯示直到 expires 的倒數計時。如果客戶離開,DELETE /bookings/holds/{reference} 會立刻釋放該時段;否則它會在 expires 時自行釋放。期間內被別人訂走的時段會回應 409 booking_slot_taken:請重新讀取可預約時段。
POST /bookings(權限範圍 bookings:manage)會預約這筆預約。
| 欄位 | 要填寫什麼 |
|---|---|
contact | 客戶的 WhatsApp 號碼,國碼在前,只用數字(或他們的企業範圍使用者 id) |
name | 客戶的姓名 |
service_id, start | 服務,以及步驟 2 中的時段 id |
hold | 如果您保留了時段,這裡填步驟 3 中保留的 reference。預約會沿用保留的參考編號,並釋放該保留 |
provider_id | 工作人員。省略時:第一位有空的人 |
email, notes | 選填。提供電子郵件後,客戶也可以透過電子郵件收到確認(在 Book-and-Pay 中開啟客戶電子郵件時) |
answers_q | 對服務自己問題的回答,依問題 id 排列。必填問題必須回答 |
notify | true(預設)會發送 WhatsApp 確認。false 則靜默預約 |
標頭 Idempotency-Key | 專屬於這次預約的值,例如您的表單提交 id。24 小時內以相同金鑰發送的相同請求,不會重複預約 |
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: booking-form-8f2c1a" \
-d '{
"contact": "61412345678",
"name": "John Smith",
"email": "john@example.com",
"service_id": "haircut",
"start": "2026-11-10T09:00",
"provider_id": "maria",
"hold": "BK-7Q3M2A",
"notes": "First visit",
"notify": true
}'async function book({ formId, phone, name, email, serviceId, slotId, providerId, holdRef }) {
const res = await fetch(`${API}/bookings`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": `booking-${formId}` },
body: JSON.stringify({
contact: phone, // digits only, country code first
name, email,
service_id: serviceId,
start: slotId, // eg "2026-11-10T09:00"
provider_id: providerId,
hold: holdRef, // leave out when you did not hold the time
notify: true,
}),
});
const json = await res.json();
if (res.status === 409 && json.error?.code === "booking_slot_taken") return { taken: true };
if (!res.ok) throw new Error(`${json.error?.code}: ${json.error?.how_to_fix} (${json.request_id})`);
return json.booking; // keep booking.id and booking.reference
}def book(form_id, phone, name, email, service_id, slot_id, provider_id=None, hold_ref=None):
body = {"contact": phone, "name": name, "email": email, "service_id": service_id,
"start": slot_id, "notify": True}
if provider_id:
body["provider_id"] = provider_id
if hold_ref:
body["hold"] = hold_ref
res = requests.post(f"{API}/bookings", json=body, timeout=10,
headers={**HEADERS, "Idempotency-Key": f"booking-{form_id}"})
data = res.json()
if res.status_code == 409 and data.get("error", {}).get("code") == "booking_slot_taken":
return None # show the free times again
if not res.ok:
raise RuntimeError(f"{data['error']['code']}: {data['error']['how_to_fix']} ({data['request_id']})")
return data["booking"] # keep booking["id"] and booking["reference"]您會收到的回應(201 Created):
{
"success": true,
"request_id": "b2mz7",
"booking": {
"id": 42,
"reference": "BK-7Q3M2A",
"status": "confirmed",
"contact": "61412345678",
"contact_name": "John Smith",
"contact_email": "john@example.com",
"service": { "id": "haircut", "name": "Haircut", "duration_min": 30 },
"start": "2026-11-09T22:00:00.000Z",
"end": "2026-11-09T22:30:00.000Z",
"timezone": "Australia/Sydney",
"source": "api",
"calendar": { "provider": "google", "event_id": "evt_1a2b3c", "url": "https://calendar.google.com/calendar/event?eid=..." },
"answers": {},
"notes": "First visit",
"provider": { "id": "maria", "name": "Maria" },
"credits_used": 0,
"created": "2026-11-06T01:12:09.000Z"
},
"note": "Booked. The customer gets the confirmation on WhatsApp (a text inside their 24 hour window, else the booking confirmation template)."
}請把 id 和 reference 與您自己的記錄放在一起。之後的每個呼叫都可以使用其中任何一個;reference 是客戶看到的簡短代碼。以相同 Idempotency-Key 重複發送的請求,會再次得到同樣的回應,並帶有標頭 Idempotent-Replayed: true。
開始時間必須是步驟 2 中的時段。POST /bookings 不會檢查您自己設定的最短預約提前時間,所以請只向客戶提供可預約時段所給出的時間(也就是客戶會看到的時間)。
在 WhatsApp 上:
attendance_confirmed 填入時間。點選 Cancel 或回覆 CANCEL 會取消預約,並發送 booking.cancelled,其中 cancelled.by: "customer"。Reschedule 讓客戶挑選新的時間,而您會收到 booking.rescheduled。對您而言: 您行事曆中的事件(calendar.url)、寄到您 Book-and-Pay 訊息中地址的電子郵件,以及這個 webhook 事件:
{
"id": "evt_Bk3k9m2Lw8Rt5Yp1Zs01",
"type": "booking.created",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"id": 42,
"reference": "BK-7Q3M2A",
"status": "confirmed",
"contact": "61412345678",
"contact_name": "John Smith",
"contact_email": "john@example.com",
"service": { "id": "haircut", "name": "Haircut", "duration_min": 30 },
"start": "2026-11-09T22:00:00.000Z",
"end": "2026-11-09T22:30:00.000Z",
"timezone": "Australia/Sydney",
"source": "api",
"calendar": { "provider": "google", "event_id": "evt_1a2b3c", "url": "https://calendar.google.com/calendar/event?eid=..." },
"answers": {},
"notes": "First visit",
"provider": { "id": "maria", "name": "Maria" },
"credits_used": 0,
"created": "2026-11-06T01:00:00.000Z",
"timestamp": "2026-11-06T01:00:00.000Z",
"hold": true
}
}source 會告訴您預約來自何處:api(您)、whatsapp_flow(客戶在 WhatsApp 預約表單中)、web(線上預約頁面)或 dashboard(您的團隊,也包括在行事曆應用程式中)。hold: true 表示這是從保留的時段建立的。如果行事曆寫入失敗,calendar.error 會說明原因;預約仍然有效。
GET /bookings/{id} 可使用 id 或參考編號:GET /bookings/BK-7Q3M2A。GET /bookings?contact=61412345678&upcoming=true 會列出某位客戶從現在起已確認的預約,最近的在前,適合用於「我的預約」頁面。GET /bookings?from=2026-11-10&to=2026-11-16 會列出某段日期範圍(status、provider_id、q 和 order=desc 可進一步篩選;用 next_cursor 和 cursor 分頁)。POST /bookings/{id}/reschedule(權限範圍 bookings:manage)會就地移動已確認的預約:id 和 reference 不變,行事曆事件隨之移動,提醒重新開始計算。start 必須是 GET /bookings/availability 或 GET /bookings/next 中的可預約時段;預約自己原本的時間視為空檔。provider_id 也可以更換工作人員("any":第一位有空的人)。
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A/reschedule \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: move-BK-7Q3M2A-2026-11-12T10:00" \
-d '{"start": "2026-11-12T10:00", "notify": true}'const res = await fetch(`${API}/bookings/BK-7Q3M2A/reschedule`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": "move-BK-7Q3M2A-2026-11-12T10:00" },
body: JSON.stringify({ start: "2026-11-12T10:00", notify: true }),
});
console.log(res.status, (await res.json()).booking);res = requests.post(f"{API}/bookings/BK-7Q3M2A/reschedule", timeout=10,
headers={**HEADERS, "Idempotency-Key": "move-BK-7Q3M2A-2026-11-12T10:00"},
json={"start": "2026-11-12T10:00", "notify": True})
print(res.status_code, res.json().get("booking"))您會收到的回應(200;已縮短,booking 的欄位與上面相同):
{
"success": true,
"request_id": "c0rs2",
"booking": {
"id": 42,
"reference": "BK-7Q3M2A",
"status": "confirmed",
"start": "2026-11-11T23:00:00.000Z",
"end": "2026-11-11T23:30:00.000Z",
"timezone": "Australia/Sydney",
"provider": { "id": "maria", "name": "Maria" }
},
"note": "Moved. The booking keeps its id and reference. The customer is told on WhatsApp."
}除非 notify 為 false,否則客戶會透過 WhatsApp 收到新時間,而您的 webhook 會收到 booking.rescheduled。409 booking_slot_taken:該時間不是空檔,請重新讀取可預約時段。
PATCH /bookings/{id}(權限範圍 bookings:manage)可以變更客戶的 name 或 email、notes、answers,或工作人員(provider_id;該時間對他們必須是空檔,否則 409 booking_slot_taken)。時間本身只能用 reschedule 變更。系統會發送 booking.updated,其中 changed 會列出變更的欄位。
curl -X PATCH https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"notes": "Allergic to ammonia", "provider_id": "tom"}'POST /bookings/{id}/cancel(權限範圍 bookings:manage)會移除行事曆事件、發送 booking.cancelled,並透過 WhatsApp 通知客戶(在他們的 24 小時視窗內用文字訊息,否則用取消範本),除非 notify 為 false。
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/BK-7Q3M2A/cancel \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"reason": "customer asked by phone", "notify": true}'您會收到的回應(200;已縮短):
{
"success": true,
"request_id": "b3nd4",
"booking": {
"id": 42,
"reference": "BK-7Q3M2A",
"status": "cancelled",
"cancelled": { "at": "2026-11-07T03:00:00.000Z", "by": "api", "reason": "customer asked by phone" }
},
"note": "Cancelled. The customer is told on WhatsApp (a text inside their 24 hour window, else the cancellation template)."
}重複取消會回應 409 booking_cancelled:請視為已完成。取消會釋放該時段,而該日候補名單上的客戶會收到該時段的提供。
POST /bookings/{id}/status 搭配 {"status": "completed"} 或 {"status": "no_show"} 會標記這筆預約("confirmed" 則改回原狀)。已完成的預約,在您開啟後續訊息功能時,會收到後續訊息(術後護理和評分按鈕);評分會以 booking.rated 送達。您沒有標記的預約,會在結束 24 小時後自動標示為已完成。
午休、休假日、暫停營業的下午:POST /calendar/blocks(權限範圍 bookings:manage)會建立沒有人可以預約的時段,適用於某位工作人員(provider_id)或整個企業(省略即可)。請提供 start 和 end(當地時間 yyyy-MM-ddTHH:mm,最長 31 天),或用 date 表示整天。既有的預約不會受到影響。
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/calendar/blocks \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: lunch-maria-2026-11-14" \
-d '{"start": "2026-11-14T12:00", "end": "2026-11-14T13:00", "provider_id": "maria", "title": "Lunch"}'const res = await fetch(`${API}/calendar/blocks`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": "lunch-maria-2026-11-14" },
body: JSON.stringify({ start: "2026-11-14T12:00", end: "2026-11-14T13:00", provider_id: "maria", title: "Lunch" }),
});
const { block } = await res.json();
console.log(block.id);res = requests.post(f"{API}/calendar/blocks", timeout=10,
headers={**HEADERS, "Idempotency-Key": "lunch-maria-2026-11-14"},
json={"start": "2026-11-14T12:00", "end": "2026-11-14T13:00",
"provider_id": "maria", "title": "Lunch"})
print(res.json()["block"]["id"])您會收到的回應(201 Created):
{
"success": true,
"request_id": "c3bk4",
"block": {
"id": 3,
"provider_id": "maria",
"title": "Lunch",
"notes": "",
"start": "2026-11-14T01:00:00.000Z",
"end": "2026-11-14T02:00:00.000Z",
"start_local": "2026-11-14T12:00",
"end_local": "2026-11-14T13:00",
"source": "api",
"created_by": "API key Planner",
"created": "2026-11-11T01:12:09.000Z",
"updated": "2026-11-11T01:12:09.000Z"
},
"note": "Blocked. No one can book that time."
}PATCH /calendar/blocks/{id} 可以變更 start、end、date、provider_id、title、notes 中的任何一項。DELETE /calendar/blocks/{id} 會移除它:該時段可以再次被預約,等候中的客戶也可以收到該時段的提供。GET /calendar/blocks?from=2026-11-14&to=2026-11-20 會列出這些封鎖。GET /calendar 會在一次回應中給您某段日期範圍的所有內容(最多 62 天):預約、封鎖、您連接的行事曆中的忙碌時間、目前保留中的時段、每天的營業時間、工作人員和服務。很適合用於您自己應用程式中的員工畫面。相關事件是 calendar.block.created 和 calendar.block.deleted。
當某一天沒有剩餘的可預約時段時,客戶可以等候空檔。請先在 Book-and-Pay 中為該服務開啟候補名單(GET /settings/booking 中的 config.services[].waitlist)。
POST /bookings/waitlist(權限範圍 bookings:manage)會把客戶放進已客滿日期的候補名單:
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/bookings/waitlist \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contact": "61412345678", "name": "Jane", "service_id": "haircut", "date": "2026-11-20"}'您會收到的回應(201 Created;已縮短):
{
"success": true,
"request_id": "w2add",
"entry": {
"id": 12,
"reference": "WL-4HT9XC",
"status": "waiting",
"service_id": "haircut",
"service_name": "Haircut",
"provider_id": "maria",
"provider_name": "Maria",
"date": "2026-11-20",
"date_label": "Fri 20 Nov 2026",
"contact": "61412345678",
"contact_name": "Jane",
"seats": 1,
"source": "api",
"notified_count": 0,
"appointment_id": null
},
"existing": false
}existing: true,所以這個呼叫可以安全地重複執行。provider_id 表示等候某一位工作人員;省略時,任何人皆可。slot_id 表示等候團體服務的某個已客滿時段,seats 表示需要一個以上的名額。email 讓提供在無法使用 WhatsApp 時透過電子郵件發出。waitlist_not_offered:請改為提供可預約時段。force: true 會略過空檔檢查。接下來會發生什麼: 當該日有時段空出來時(取消、改期、移除封鎖,以及每 5 分鐘一次的檢查),等候中的客戶會收到一則 WhatsApp 訊息,附上可預約該時段的連結(視窗已關閉時用候補名單範本,或用電子郵件)。第一個預約的人得到該時段。您的 webhook 會收到 waitlist.notified,其中帶有 offer:
{
"id": "evt_Wl3k9m2Lw8Rt5Yp1Zs02",
"type": "waitlist.notified",
"created": "2026-11-13T01:00:00.000Z",
"number": "4976659348270",
"data": {
"id": 12,
"reference": "WL-4HT9XC",
"status": "notified",
"service_id": "haircut",
"service_name": "Haircut",
"provider_id": "maria",
"provider_name": "Maria",
"date": "2026-11-20",
"date_label": "Fri 20 Nov 2026",
"slot_id": "",
"time_label": "",
"contact": "61412345678",
"contact_name": "Jane",
"contact_email": "",
"seats": 1,
"source": "api",
"notified_count": 1,
"notified_at": "2026-11-13T01:00:00.000Z",
"appointment_id": null,
"note": "Offered Fri 20 Nov 2026 10:30 AM on WhatsApp",
"created": "2026-11-13T01:00:00.000Z",
"updated": "2026-11-13T01:00:00.000Z",
"day": "2026-11-20",
"slot_local": "",
"contact_masked": "•••• 5678",
"created_at": "2026-11-13T01:00:00.000Z",
"timestamp": "2026-11-13T01:00:00.000Z",
"offer": {
"slot_id": "2026-11-20T10:30",
"start": "2026-11-19T23:30:00.000Z",
"date_label": "Fri 20 Nov 2026",
"time_label": "10:30 AM",
"channel": "whatsapp",
"manual": false
}
}
}項目的 status 是 waiting、notified(已提供時段,最多 3 次提供)、booked(客戶當天預約了該服務;appointment_id 是預約)、expired(該日已過)、removed,或 pending_confirm(在您的公開預約頁面加入,但尚未在 WhatsApp 上確認)。
GET /bookings/waitlist 會列出有效的項目,最近的日期在前(from、to、service_id、contact、include_closed=true)。POST /bookings/waitlist/{reference}/remove 會把客戶從名單中移除,不會向他們發送訊息,並發送 waitlist.removed。用 POST /webhooks(權限範圍 webhooks:manage)註冊一次 webhook,或在 API 金鑰頁面註冊。該號碼的每個 webhook 都會收到每個事件:請依 type 挑出您需要的,並對其餘事件回應 2xx。使用 API 建立 WhatsApp 聊天機器人逐步說明了註冊、簽章檢查和測試事件;POST /webhooks/{id}/test 搭配 {"type": "booking.created"} 會發送該事件的範例。
| 事件 | 時機 |
|---|---|
booking.created | 預約已建立:在 WhatsApp 表單中、在線上頁面上、在儀表板上,或透過 API |
booking.rescheduled | 預約已改期;舊的時間在 rescheduled_from 中 |
booking.cancelled | 預約已取消;cancelled.by 是 customer、business、api 或 system |
booking.updated | 姓名、電子郵件、備註、回答或工作人員已變更;changed 會列出欄位 |
booking.rated | 客戶為已完成的預約評分 |
booking.paid, booking.refunded | 預約的線上付款或訂金已付款,或已退款 |
booking.note.created | 加入了一則內部備註 |
calendar.block.created, calendar.block.deleted | 時段已封鎖,或封鎖已移除 |
waitlist.joined, waitlist.notified, waitlist.removed | 客戶加入了候補名單、收到時段提供,或被移出 |
事件會針對每一筆預約發出,而不只是您自己建立的那些:在 WhatsApp 表單中預約,或以回覆取消的客戶,也會傳到您的系統。booking.rescheduled 如下所示:
{
"id": "evt_Bk3k9m2Lw8Rt5Yp1Zs03",
"type": "booking.rescheduled",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"id": 42,
"reference": "BK-7Q3M2A",
"status": "confirmed",
"contact": "61412345678",
"contact_name": "Sample Contact",
"contact_email": "sample@example.com",
"service": { "id": "haircut", "name": "Haircut", "duration_min": 30 },
"start": "2026-11-09T23:00:00.000Z",
"end": "2026-11-09T23:30:00.000Z",
"timezone": "Australia/Sydney",
"source": "whatsapp_flow",
"calendar": { "provider": "google", "event_id": "evt_sample_1", "url": "https://calendar.google.com/calendar/event?eid=sample" },
"answers": { "notes": "Please keep it short" },
"notes": "Please keep it short",
"provider": { "id": "maria", "name": "Maria" },
"credits_used": 0,
"created": "2026-11-06T01:00:00.000Z",
"timestamp": "2026-11-06T01:00:00.000Z",
"rescheduled_from_id": 41,
"rescheduled_from": { "id": 41, "reference": "BK-2KD8XQ", "start": "2026-11-08T23:00:00.000Z", "end": "2026-11-08T23:30:00.000Z" }
}
}透過 API 改期會保留 id 和參考編號。在 WhatsApp 上改期的客戶,會得到一筆取代舊預約的新預約,如這個範例所示:請用 rescheduled_from.id(或它的 reference)找到您的記錄,並儲存新的 id 和 reference。
Book-and-Pay 透過您自己的 Stripe 或 PayPal 帳號收款,帳號在它的付款頁面連接:每項服務的價格、必須付款、選擇性付款或不需付款,以及您想要的話還可以設定訂金。若要對預約收取訂金或其他金額,用預約的 booking_id 呼叫 POST /payments/links 就會產生付款頁面;使用 send: true 且客戶在 24 小時視窗內時,他們也會在對話中收到附有 Pay 按鈕的訊息。當服務商確認後,您的 webhook 會收到 payment.paid;預約自己的線上付款或訂金(在服務上設定)則回報 booking.paid。逐步說明:在 WhatsApp 對話中要求付款。
您不必自己建立每一個畫面:
contact 呼叫 POST /bookings/links,會產生通往線上預約頁面的連結(請在 Book-and-Pay 的「線上預約」分頁中開啟)。purpose 為 book、reschedule(搭配 booking_id)或 manage(他們即將到來的預約)。回應中的 link.url 由您來發送。{"contact": "61412345678"} 呼叫 POST /flows/{key}/send,會把已發布的預約表單發送給過去 24 小時內寫過訊息給您的客戶。預約會以 booking.created 傳回,其中 source: "whatsapp_flow"。兩者最終都會產生與上述呼叫相同的預約、確認、提醒和事件。
金鑰留在您的伺服器上。 您的網頁或應用程式只與您的伺服器溝通,只有您的伺服器會呼叫 app2email。只顯示可預約時段的金鑰需要 messages:read;負責預約的金鑰需要 bookings:manage。金鑰可以限制為只能從您伺服器的 IP 位址使用、設定每日上限,或設定到期。
每筆預約只預約一次。 請在 POST /bookings、POST /bookings/holds、POST /bookings/{id}/reschedule 和 POST /calendar/blocks 上發送 Idempotency-Key,用您這邊獨一無二的資料組成(表單提交 id)。24 小時內相同的金鑰和相同的內容:會回傳第一次的回應,並帶有 Idempotent-Replayed: true。相同的金鑰但內容不同:422 idempotency_key_reused。409 idempotency_request_in_progress:請等待後,用相同的金鑰重試。POST /bookings/waitlist 不需要金鑰:重複請求會回應 existing: true。
預期時段會被訂走。 在顯示時段和預約之間,WhatsApp 上的某個人可能先訂走該時段。請用 POST /bookings/holds 保留,遇到 409 booking_slot_taken 時,請重新顯示可預約時段,而不是顯示錯誤頁面。
把時區處理正確。 請求中的時段 id 和 start 是企業所在時區的當地時間(每個回應中的 timezone);回應和事件中的 start 和 end 則是 UTC。請向客戶顯示 title、start_local 或企業所在時區,而不是他們自己瀏覽器的時區。
驗證每個事件。 用 webhook 的 whsec_... 密鑰,對原始內容檢查 X-App2email-Signature,並拒絕早於 5 分鐘的 t。在 10 秒內回應 2xx;失敗的事件會在大約 32 小時內重新發送。
依真實 id 去除重複。 依事件 id(也在 X-App2email-Delivery 中)丟棄重複的事件。以 id 和 reference 儲存預約,並在客戶於 WhatsApp 上改期時,沿著 rescheduled_from 追蹤。事件可能亂序送達:請比較 timestamp。
遵守限制。 每個回應都有 X-RateLimit-Limit、X-RateLimit-Remaining、X-RateLimit-Reset 和 X-RateLimit-Policy。超過限制時:429 rate_limited 並附帶 Retry-After;等待該段時間後再重試。請快取服務,並在客戶開啟頁面時讀取可預約時段,而不是每次按鍵都讀取。範圍:availability 最多 32 天,calendar 最多 62 天。請參閱限制。
讓 Book-and-Pay 處理訊息。 確認、提醒,以及已改期和已取消的通知,在 24 小時視窗內使用自由文字,在視窗之外則使用 Book-and-Pay 已核准的實用範本。上線之前,請在範本頁面確認 Meta 已核准它們。只有在您自己告知客戶時,才使用 notify: false,並在您的表單上告訴客戶,確認和提醒會透過 WhatsApp 送達。
行銷之前先徵求同意。 確認和提醒是關於客戶所預約的預約。「該回診了」之類的訊息屬於行銷:只發送給同意接收行銷訊息的客戶,且「請勿聯絡」名單適用。
| 您看到的情況 | 原因 | 解決方法 |
|---|---|---|
403 booking_not_enabled | 這個號碼尚未設定 Book-and-Pay | 在 Book-and-Pay 頁面設定並開啟(https://www.app2email.com/dashboard/app/book)。如果已開啟但錯誤仍然存在,請帶著 request_id 寫信給 support@app2email.com |
403 insufficient_scope | 金鑰缺少 bookings:manage(讀取則缺少 messages:read) | 在 API 金鑰頁面建立具備該權限範圍的金鑰;預設金鑰沒有它 |
403 sandbox_key | 沙盒金鑰無法預約、保留、改期、取消、封鎖或變更候補名單 | 使用一般金鑰;沙盒金鑰留著用於讀取呼叫 |
403 not_in_instant_sandbox | 示範號碼沒有預約相關呼叫 | 使用已設定 Book-and-Pay 的您自己的號碼 |
401 missing_api_key, invalid_api_key, api_key_revoked | 沒有金鑰、金鑰錯誤,或金鑰已過期 | 發送 Authorization: Bearer YOUR_API_KEY,且網址中使用該金鑰所屬的號碼 |
403 plan_not_allowed, service_not_live | 沒有付費方案,或服務已暫停 | 選擇方案;暫停的服務可在設定頁面按「Go Live」恢復上線 |
400 invalid_service | service_id 缺少,或不是已開啟的服務 | 從 GET /bookings/services 取得 id |
400 invalid_start | start 缺少,或不是時段 | 從 GET /bookings/availability 取得時段 id(yyyy-MM-ddTHH:mm,企業所在時區)後發送 |
400 invalid_answers | 服務的某個必填問題沒有回答 | 在 answers_q 中發送每個必填問題 |
400 invalid_addons, invalid_guests | 服務不提供的加購項目,或同行人數或名額過多 | 使用服務自己的加購項目 id;同行人數不要超過服務的上限 |
400 invalid_range, range_too_large | from 晚於 to,或範圍太長 | 可預約時段最多 32 天,行事曆最多 62 天 |
400 invalid_block | 結束時間不晚於開始時間、封鎖超過 31 天,或工作人員不存在 | 修正訊息中指出的欄位;provider_id 來自 GET /bookings/staff |
404 booking_not_found, block_not_found, hold_not_found, waitlist_not_found | 這個號碼上沒有這筆預約、封鎖、保留或候補項目 | 檢查 id 或參考編號(BK-...、WL-...)以及網址中的號碼 |
409 booking_slot_taken | 該時間已不是空檔 | 重新讀取可預約時段,讓客戶挑選另一個時間 |
409 hold_expired | 保留的時段已過期、已被釋放,或已被預約 | 重新保留該時段,或讀取它變成的預約 |
409 booking_cancelled | 預約已經取消 | 不需要處理;如果客戶想要另一個時間,請建立新的預約 |
409 waitlist_not_offered | 服務沒有候補名單、該日仍有可預約時段、已休息或太遠,或候補名單已滿 | 為該服務開啟候補名單、選擇已客滿的日期(或發送 force: true),或改為預約可預約的時段 |
409 waitlist_not_set_up | 候補名單在我們這邊尚未可用 | 請稍後再試 |
403 link_not_usable | 預約連結已過期、已被撤銷或已用完,或線上預約頁面已關閉 | 用 POST /bookings/links 建立新的連結,或開啟線上頁面 |
422 idempotency_key_reused | 相同的 Idempotency-Key,但內容不同 | 不同的預約請使用新的金鑰 |
429 rate_limited | 此金鑰的呼叫太多 | 等待 Retry-After 秒,然後重試 |
| 客戶沒有收到 WhatsApp 確認 | notify 為 false,或預約範本尚未核准 | 檢查範本頁面;message.status 和 message.failed 事件會顯示訊息發生了什麼事 |
每個回應都有一個 request_id。GET /requests/{id} 會顯示為它記錄的內容,support@app2email.com 也能查到。所有代碼:錯誤。
可以。工作人員在 Book-and-Pay 中設定,各自有自己的時段,也可以有自己的行事曆(如果他們願意)。GET /bookings/staff 會列出他們,provider_id 可用來查詢某個人的時段或與他們預約,省略則表示「任何有空的人」。連接的行事曆中的忙碌時間絕不會被提供。
可以,只要服務有名額。GET /bookings/availability 搭配 seats 只會顯示還有那麼多名額的時段,而 POST /bookings 可接受 guests。已客滿的團體時段可以有自己的候補名單(POST /bookings/waitlist 上的 slot_id)。
可以。MCP 伺服器 https://api.app2email.com/mcp/book-and-pay 和 https://api.app2email.com/mcp/calendar 以工具提供相同的呼叫(get_booking_availability、create_booking、cancel_booking、find_next_booking_slots、hold_booking_slot、reschedule_booking、create_time_block、add_to_waitlist ...)。請參閱用 MCP 讓 AI 代理管理您的 WhatsApp 和 MCP。