在您自己的网站或应用上显示空闲时间,通过 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 下添加 |
Default 密钥(在密钥有权限设置之前创建的)没有 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 表示。默认:今天及之后的 6 天;最多 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 号码,国家代码在前,只写数字(或者他们的 business-scoped 用户 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 会取消预约,并发送带有 cancelled.by: "customer" 的 booking.cancelled。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 会收到带有 offer 的 waitlist.notified:
{
"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 账户收款,在它的 Payments 页面连接:每项服务一个价格,付款可设为必需、可选或没有,并且可以设置押金。要为某个预约请求押金或其他金额,用带有该预约 booking_id 的 POST /payments/links 创建付款页面;使用 send: true 且客户处于其 24 小时窗口内时,他们也会在对话中收到带有 Pay 按钮的消息。当服务商确认后,您的 webhook 会收到 payment.paid;预约自己的在线付款或押金(在服务上设置)则报告 booking.paid。分步说明:在 WhatsApp 对话中请求付款。
您不必自己构建每个页面:
contact 调用 POST /bookings/links,会生成指向在线预约页面的链接(请在 Book-and-Pay 的 Online booking 标签页中开启它)。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 已批准的 utility 模板。上线之前,请在 Templates 页面检查 Meta 是否已批准它们。只有当您自己通知客户时才发送 notify: false,并在您的表单上告诉客户确认和提醒会通过 WhatsApp 送达。
营销之前先征得同意。 确认消息和提醒针对的是客户预订的那个预约。“该来下一次了”这样的消息属于营销:只发给同意接收营销的客户,并且 Do Not Call 名单适用。
| 您看到的现象 | 原因 | 解决方法 |
|---|---|---|
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 密钥页面创建带有该权限范围的密钥;Default 密钥没有它 |
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,URL 中使用该密钥对应的号码 |
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,或者范围太长 | availability 最多 32 天,calendar 最多 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-...)以及 URL 中的号码 |
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,或者预约模板尚未获批 | 检查 Templates 页面;message.status 和 message.failed 事件会显示这条消息发生了什么 |
每个响应都有一个 request_id。GET /requests/{id} 会显示为它记录的内容,support@app2email.com 也可以查到。所有错误码:错误。
可以。员工在 Book-and-Pay 中设置,每人有自己的工作时间,如果愿意还可以有自己的日历。GET /bookings/staff 会列出他们,provider_id 用于请求某个人的时间或与其预订,省略则表示“任何有空的人”。已连接日历中的忙碌时间永远不会被提供。
可以,只要服务有名额。带有 seats 的 GET /bookings/availability 只会显示剩余名额足够的时间,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。