Push NotificationsNotification Endpoint

Đăng ký Endpoint

Đăng ký hoặc cập nhật endpoint nhận thông báo cho khách hàng đang đăng nhập.

Endpoint

POST /site/notificationendpoints/register

Headers

KeyValueBắt buộcMô tả
SiteTenantId{tenant_id}CóID của công ty/tenant.
SiteAuthorization{jwt_token}CóToken định danh khách hàng sau khi đăng nhập.

Workflow & Logic

API này cho phép khách hàng đang đăng nhập đăng ký (hoặc cập nhật) endpoint nhận thông báo đẩy (push notification) của mình.

Quy trình xử lý

  1. Xác thực Session: Kiểm tra JWT token và xác định company_id + customer_id từ token SiteAuthorization.

  2. Validate dữ liệu: Kiểm tra các trường bắt buộc (channel_type, endpoint_value, app_code).

  3. Tự động gán ngữ cảnh:

    • company_id → lấy từ session (không cần truyền).
    • owner_type → luôn là 3 (CUSTOMER).
    • owner_id → lấy từ customer_id trong session.
  4. Upsert bằng Owner-Scope:

    • Nếu đã tồn tại endpoint cùng owner-scope → cập nhật endpoint_value, provider, platform, device_id, đặt status = ACTIVE.
    • Nếu chưa tồn tại → tạo mới.
    • Nếu endpoint_value (token) đang được đăng ký cho owner khác → bản ghi cũ bị xóa (token đã chuyển sang thiết bị/khách hàng mới).
  5. Trả kết quả: Trả về đối tượng endpoint vừa tạo/cập nhật.

Request Body

{
  "channel_type": 9,       // Loại kênh (9 = Push Notification)
  "provider": "fcm",       // Nhà cung cấp (mặc định: "fcm")
  "endpoint_value": "fcm_token_string...", // FCM registration token (bắt buộc)
  "app_code": "pos",       // Mã ứng dụng (bắt buộc)
  "platform": "android",   // Nền tảng thiết bị
  "device_id": "device-uuid-string" // UUID thiết bị
}

Response Schema (200)

Trả về Notification Endpoint Object.

{
  "company_id": 123,
  "creator_id": 0,
  "id": 456,
  "owner_type": 3,
  "owner_id": 789,
  "channel_type": 9,
  "provider": "fcm",
  "endpoint_value": "fcm_token_string...",
  "app_code": "pos",
  "platform": "android",
  "device_id": "device-uuid-string",
  "status": 1,
  "error_message": "",
  "ip_address": "192.168.1.1",
  "date_last_used": 0,
  "date_created": 1740300000,
  "date_modified": 0
}

Lỗi thường gặp (422)

Mã lỗiMô tả
error_channel_type_requiredchannel_type không được để trống hoặc phải > 0.
error_endpoint_value_requiredendpoint_value không được để trống.
error_app_code_requiredapp_code không được để trống.

Lỗi hệ thống (500)

Mã lỗiMô tả
error_register_endpointKhông thể đăng ký endpoint.

Error Codes

HTTPMã lỗiMô tả
401error_customer_login_requiredThiếu SiteAuthorization hoặc token không hợp lệ/hết hạn.
401error_customer_company_mismatchToken khách hàng không thuộc shop của SiteTenantId.
404error_company_not_found_from_site_tenant_idSiteTenantId không hợp lệ hoặc shop không còn hoạt động.

On this page