Skip to main content

Start Table Session

POST /api/customer/:branchSlug/:tableCode/session Request access to a table by creating a pending session. This is similar to /register but with simpler parameters.
This endpoint is public and does not require authentication.

URL Parameters

branchSlug
string
required
Branch slug identifier (e.g., downtown-lima)
tableCode
string
required
Unique table QR code in format {branchSlug}-{tableNumber}

Request Body

customerName
string
required
Customer’s full name (1-255 characters)
customerPhone
string
Customer’s phone number (optional, max 20 characters)

Response

success
boolean
Indicates if the request was successful
data
object
session
object
Created session object with pending status
token
string
Customer JWT token for authenticated requests
sessionId
string
Session UUID for status polling
existing
boolean
Present only if table already has an active session. When true, you’re joining an existing session.

Example

curl -X POST https://api.restai.com/api/customer/downtown-lima/downtown-lima-15/session \
  -H "Content-Type: application/json" \
  -d '{
    "customerName": "Carlos Rodriguez",
    "customerPhone": "+51912345678"
  }'
{
  "success": true,
  "data": {
    "session": {
      "id": "660e8400-e29b-41d4-a716-446655440000",
      "table_id": "123e4567-e89b-12d3-a456-426614174000",
      "customer_name": "Carlos Rodriguez",
      "customer_phone": "+51912345678",
      "status": "pending",
      "started_at": "2024-03-15T19:00:00Z"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "sessionId": "660e8400-e29b-41d4-a716-446655440000"
  }
}

Check Session Status

GET /api/customer/:branchSlug/:tableCode/check-session Check if a table currently has an active or pending session. Useful for UI flows to determine if the customer should join an existing session or create a new one.
This endpoint is public and does not require authentication.

URL Parameters

branchSlug
string
required
Branch slug identifier
tableCode
string
required
Unique table QR code

Response

success
boolean
Always true
data
object
hasSession
boolean
true if table has an active or pending session
status
string
Session status: active or pending. Only present when hasSession is true.
sessionId
string
Session UUID. Only present when hasSession is true.
customerName
string
Name of the customer who started the session. Only present when hasSession is true.

Examples

No Active Session
curl -X GET https://api.restai.com/api/customer/downtown-lima/downtown-lima-15/check-session
{
  "success": true,
  "data": {
    "hasSession": false
  }
}
Active Session Exists
{
  "success": true,
  "data": {
    "hasSession": true,
    "status": "active",
    "sessionId": "550e8400-e29b-41d4-a716-446655440000",
    "customerName": "Juan Perez"
  }
}
Pending Approval
{
  "success": true,
  "data": {
    "hasSession": true,
    "status": "pending",
    "sessionId": "550e8400-e29b-41d4-a716-446655440000",
    "customerName": "Maria Garcia"
  }
}

Poll Session Status

GET /api/customer/:branchSlug/:tableCode/session-status/:sessionId Poll the approval status of a specific session. Use this to check if staff has approved or rejected your request.
This endpoint is public and does not require authentication.

URL Parameters

branchSlug
string
required
Branch slug identifier
tableCode
string
required
Unique table QR code
sessionId
string
required
Session UUID from the registration response

Response

success
boolean
Indicates if the request was successful
data
object
id
string
Session UUID
status
string
Current session status: pending, active, rejected, or completed
customer_name
string
Customer’s name

Example

curl -X GET https://api.restai.com/api/customer/downtown-lima/downtown-lima-15/session-status/550e8400-e29b-41d4-a716-446655440000
{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "status": "active",
    "customer_name": "Maria Garcia"
  }
}

Customer Approval Workflow

1. Customer Scans QR Code

The QR code contains: https://app.restai.com/{branchSlug}/{tableCode}

2. Check Existing Session

GET /api/customer/:branchSlug/:tableCode/check-session
  • If hasSession: false → Proceed to step 3
  • If hasSession: true and status: active → Join existing session
  • If hasSession: true and status: pending → Show “waiting for approval” message

3. Request Access

POST /api/customer/:branchSlug/:tableCode/register
Customer submits their information. Receive:
  • Session ID
  • Customer token
  • Pending status

4. Wait for Approval

Option A: WebSocket (Recommended) Connect to WebSocket and subscribe to session:{sessionId} channel:
ws.subscribe(`session:${sessionId}`);
ws.on('session:approved', () => {
  // Session approved, navigate to menu
});
ws.on('session:rejected', () => {
  // Session rejected, show error
});
Option B: Polling Poll every 3-5 seconds:
GET /api/customer/:branchSlug/:tableCode/session-status/:sessionId
Check if status changed to active or rejected.

5. Session Approved

When status becomes active:
  1. Store the customer token
  2. Navigate to menu
  3. Use token for all subsequent requests

6. Place Orders

Use the customer token:
POST /api/customer/orders \
  -H "Authorization: Bearer {customerToken}"

Error Responses

404 NOT_FOUND
Branch, table, or session not found
{
  "success": false,
  "error": {
    "code": "NOT_FOUND",
    "message": "Sesion no encontrada"
  }
}
409 SESSION_PENDING
Table already has a pending session
{
  "success": false,
  "error": {
    "code": "SESSION_PENDING",
    "message": "Esta mesa esta en espera de aprobacion"
  }
}

Staff Approval Process

On the staff side:
  1. Notification: Staff receives WebSocket event session:pending
  2. Review: Staff views pending session with customer details
  3. Action: Staff approves via PATCH /api/tables/sessions/:id/approve or rejects via PATCH /api/tables/sessions/:id/reject
  4. Broadcast: System broadcasts approval/rejection to customer via WebSocket

Security Notes

  • Customer tokens expire after 4 hours (configurable)
  • Tokens are scoped to specific table and session
  • Once session ends, token becomes invalid
  • Customer tokens have role: "customer" and limited permissions

Build docs developers (and LLMs) love