Spaces:
Running
Running
File size: 7,331 Bytes
2e76228 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | # E-commerce Appointments API Quick Reference
## Base URL
```
/appointments
```
## Endpoints
### 1. Book Appointment
```http
POST /appointments/book
```
**Request:**
```json
{
"merchant_id": "5starsaloon",
"appointment_date": "2026-02-10",
"start_time": "14:00",
"services": [
{
"service_id": "service_123",
"service_name": "Hair Cut & Styling",
"duration_minutes": 60,
"price": 500.0,
"staff_id": "staff_456",
"staff_name": "John Doe"
}
],
"customer_name": "Jane Smith",
"customer_phone": "+919876543210",
"customer_email": "jane@example.com",
"notes": "First time customer"
}
```
**Response:**
```json
{
"success": true,
"message": "Appointment booked successfully",
"appointment": {
"appointment_id": "uuid",
"merchant_id": "5starsaloon",
"customer_id": "customer_123",
"status": "booked",
...
}
}
```
---
### 2. Get Appointment
```http
GET /appointments/{appointment_id}
```
**Response:**
```json
{
"appointment_id": "uuid",
"merchant_id": "5starsaloon",
"customer_id": "customer_123",
"customer_name": "Jane Smith",
"customer_phone": "+919876543210",
"appointment_date": "2026-02-10",
"start_time": "14:00",
"end_time": "15:00",
"total_duration": 60,
"services": [...],
"status": "booked",
"total_amount": 500.0,
"currency": "INR"
}
```
---
### 3. List Appointments (Standard with Projection Support)
```http
POST /appointments/list
```
**Request (Full Response):**
```json
{
"merchant_id": "5starsaloon",
"status": "booked",
"from_date": "2026-02-01",
"to_date": "2026-02-28",
"limit": 20,
"offset": 0
}
```
**Request (With Projection - Minimal Response):**
```json
{
"merchant_id": "5starsaloon",
"status": "booked",
"limit": 20,
"offset": 0,
"projection_list": ["appointment_id", "customer_name", "start_time", "status"]
}
```
**Response (Full):**
```json
{
"appointments": [
{
"appointment_id": "uuid",
"merchant_id": "5starsaloon",
"customer_name": "Jane Smith",
...
}
],
"pagination": {
"limit": 20,
"offset": 0,
"total": 5
}
}
```
**Response (With Projection):**
```json
{
"items": [
{
"appointment_id": "uuid",
"customer_name": "Jane Smith",
"start_time": "2026-02-10T14:00:00",
"status": "booked"
}
],
"total": 5,
"pagination": {
"limit": 20,
"offset": 0,
"total": 5
}
}
```
---
### 4. Get Available Slots
```http
POST /appointments/available-slots
```
**Request:**
```json
{
"merchant_id": "5starsaloon",
"appointment_date": "2026-02-10",
"service_duration": 60,
"staff_id": "staff_456"
}
```
**Response:**
```json
{
"merchant_id": "5starsaloon",
"appointment_date": "2026-02-10",
"slots": [
{
"start_time": "09:00",
"end_time": "09:30",
"available": true
},
{
"start_time": "09:30",
"end_time": "10:00",
"available": false
}
],
"business_hours": {
"open": "09:00",
"close": "18:00"
}
}
```
---
### 5. Cancel Appointment
```http
DELETE /appointments/{appointment_id}/cancel
```
**Request:**
```json
{
"cancellation_reason": "Customer requested reschedule"
}
```
**Response:**
```json
{
"success": true,
"message": "Appointment cancelled successfully",
"appointment": {
"appointment_id": "uuid",
"status": "cancelled",
...
}
}
```
---
### 6. Get My Appointments
```http
GET /appointments/customer/my-appointments?limit=20&offset=0
```
**Response:**
```json
{
"appointments": [...],
"pagination": {
"limit": 20,
"offset": 0,
"total": 5
}
}
```
---
## Filter Options for List Endpoint
| Filter | Type | Description |
|--------|------|-------------|
| `merchant_id` | string | Filter by merchant |
| `customer_id` | string | Filter by customer |
| `appointment_date` | date | Filter by specific date |
| `status` | enum | Filter by status (booked, confirmed, cancelled, completed, no_show) |
| `from_date` | date | Filter from date (inclusive) |
| `to_date` | date | Filter to date (inclusive) |
| `limit` | int | Max records (1-100, default: 20) |
| `offset` | int | Records to skip (default: 0) |
| `projection_list` | array | Fields to include (optional) |
---
## Projection List Fields
Available fields for projection:
- `appointment_id`
- `merchant_id`
- `customer_id`
- `customer_name`
- `customer_phone`
- `status`
- `start_time`
- `end_time`
- `notes`
- `created_by`
**Note:** When using `projection_list`, services are NOT included. Use full response to get service details.
---
## Status Values
| Status | Description |
|--------|-------------|
| `booked` | Initial state when customer books |
| `confirmed` | Merchant confirms the booking |
| `cancelled` | Customer or merchant cancels |
| `completed` | Service completed |
| `billed` | Payment processed (POS only) |
| `no_show` | Customer didn't show up |
---
## Error Responses
### 400 Bad Request
```json
{
"detail": "Appointment time must be in the future"
}
```
### 404 Not Found
```json
{
"detail": "Appointment not found"
}
```
### 500 Internal Server Error
```json
{
"detail": "Failed to book appointment"
}
```
---
## Performance Tips
1. **Use Projection List**: Reduce payload size by 50-90%
```json
{
"projection_list": ["appointment_id", "customer_name", "start_time"]
}
```
2. **Limit Results**: Use pagination for large datasets
```json
{
"limit": 10,
"offset": 0
}
```
3. **Filter Wisely**: Use specific filters to reduce query time
```json
{
"merchant_id": "5starsaloon",
"appointment_date": "2026-02-10",
"status": "booked"
}
```
---
## Integration Examples
### React/Next.js
```typescript
// Book appointment
const response = await fetch('/appointments/book', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
merchant_id: '5starsaloon',
appointment_date: '2026-02-10',
start_time: '14:00',
services: [{ service_id: 'svc_123', ... }],
customer_name: 'Jane Smith',
customer_phone: '+919876543210'
})
});
// List with projection
const response = await fetch('/appointments/list', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
merchant_id: '5starsaloon',
limit: 10,
projection_list: ['appointment_id', 'customer_name', 'start_time']
})
});
```
### Python
```python
import requests
# Book appointment
response = requests.post(
'http://localhost:8000/appointments/book',
json={
'merchant_id': '5starsaloon',
'appointment_date': '2026-02-10',
'start_time': '14:00',
'services': [{'service_id': 'svc_123', ...}],
'customer_name': 'Jane Smith',
'customer_phone': '+919876543210'
}
)
# List with projection
response = requests.post(
'http://localhost:8000/appointments/list',
json={
'merchant_id': '5starsaloon',
'limit': 10,
'projection_list': ['appointment_id', 'customer_name', 'start_time']
}
)
```
---
## Notes
- All timestamps are in UTC
- Customer authentication via JWT (TODO: implement)
- Shared database with POS appointments
- Source field automatically set to 'online'
- Booking channel automatically set to 'app'
|