Ứng dụng & OAuth

Có hai cách xác thực. Làm app cho nhiều khách thì dùng OAuth: mỗi workspace cài app và đồng ý cấp quyền. Nối hệ thống của chính workspace mình thì dùng API key.

Chọn cách xác thực

App OAuthAPI key
Dành choĐối tác làm app cho nhiều workspaceMột workspace tự nối hệ thống của mình
HeaderAuthorization: Bearer …X-Api-Key: …
QuyềnGiao của quyền app xin, quyền app được phép và quyền workspace đồng ýQuyền chọn lúc tạo khoá
Hạn dùngToken 1 giờ, hết hạn thì lấy lạiTới khi thu hồi

API key →

Lấy access token (client credentials)

Sau khi workspace cài app, máy chủ của bạn đổi client_id + client_secret lấy token cho từng workspace.

curl
curl -X POST https://api.nextx.vn/api/v1/iam/oauth2/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET" \
  -d "workspace_id=WORKSPACE_GUID" \
  -d "scope=crm.contacts.view sales.orders.view"

Phản hồi:

JSON
{
  "access_token": "eyJhbGciOiJSUzI1Ni...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "crm.contacts.view sales.orders.view"
}
  • scope thực cấp = requested ∩ allowed (của app) ∩ granted (workspace consent).
  • Phản hồi có trường refresh_token nhưng luôn rỗng — không dùng để gia hạn. Token hết hạn thì gọi lại endpoint này.
  • workspace_id = GUID của workspace đã cài app (mỗi workspace 1 token riêng).

Link cài và đồng ý cấp quyền

Workspace cài app qua link cài; màn đồng ý liệt kê đúng các scope app xin. Thử ngay trên workspace của bạn ở Development mode, rồi Publish để khách khác cài được.

Xem các bước trong Bắt đầu nhanh →

Scope (quyền)

Scope = mã quyền dạng service.resource.verb, verb là view (đọc) hoặc manage (ghi). App chỉ xin được scope, workspace mới là bên đồng ý cấp.

CRM

crm.contacts.viewcrm.contacts.createcrm.opportunities.viewcrm.opportunities.managecrm.reports.viewcrm.tasks.manage

Chat đa kênh

comm.conversations.handle

Bán hàng

sales.orders.viewsales.products.viewsales.customers.view

Office

office.base.record.viewoffice.base.record.manageoffice.approval.instance.viewoffice.approval.instance.manage

Nhân sự

hrm.attendance_devices.viewhrm.attendance_raw_punches.view

DMS

dms.catalog.viewdms.checkins.viewdms.daily_plans.viewdms.outlets.viewdms.orders.viewdms.routes.view

Tổng đài

call.agents.viewcall.campaigns.viewcall.call_flows.viewcall.ivr_flows.viewcall.phone_numbers.viewcall.calls.viewcall.queues.view

Marketing

marketing.email_campaigns.viewmarketing.email_templates.viewmarketing.integrations.viewmarketing.reports.viewmarketing.sender_profiles.view

Thanh toán

payment.intents.viewpayment.refunds.viewpayment.transactions.viewpayment.subscriptions.viewpayment.reports.view

Hoá đơn điện tử

einvoice.invoices.vieweinvoice.series.vieweinvoice.reports.vieweinvoice.settings.view