Ứ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 OAuth | API key | |
|---|---|---|
| Dành cho | Đối tác làm app cho nhiều workspace | Một workspace tự nối hệ thống của mình |
| Header | Authorization: Bearer … | X-Api-Key: … |
| Quyền | Giao 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ùng | Token 1 giờ, hết hạn thì lấy lại | Tới khi thu hồi |
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"
}scopethực cấp = requested ∩ allowed (của app) ∩ granted (workspace consent).- Phản hồi có trường
refresh_tokennhư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.manageChat đa kênh
comm.conversations.handleBán hàng
sales.orders.viewsales.products.viewsales.customers.viewOffice
office.base.record.viewoffice.base.record.manageoffice.approval.instance.viewoffice.approval.instance.manageNhân sự
hrm.attendance_devices.viewhrm.attendance_raw_punches.viewDMS
dms.catalog.viewdms.checkins.viewdms.daily_plans.viewdms.outlets.viewdms.orders.viewdms.routes.viewTổng đài
call.agents.viewcall.campaigns.viewcall.call_flows.viewcall.ivr_flows.viewcall.phone_numbers.viewcall.calls.viewcall.queues.viewMarketing
marketing.email_campaigns.viewmarketing.email_templates.viewmarketing.integrations.viewmarketing.reports.viewmarketing.sender_profiles.viewThanh toán
payment.intents.viewpayment.refunds.viewpayment.transactions.viewpayment.subscriptions.viewpayment.reports.viewHoá đơn điện tử
einvoice.invoices.vieweinvoice.series.vieweinvoice.reports.vieweinvoice.settings.view