Tài liệu tích hợp API và webhook

Trang tóm tắt cách hệ thống đẩy sự kiện lead, site và commerce sang CRM hoặc hệ thống vận hành ngoài qua outbox/webhook.

Sự kiện MVP Các event này đã có đường đi qua outbox/webhook hoặc đang là hợp đồng tên sự kiện cho CRM ngoài.

  • lead.created

    Tạo lead mới từ form contact hoặc CTA public.

  • lead.updated

    Cập nhật pipeline, priority, note hoặc follow-up trong admin lead CRM.

  • site.provisioned

    Dùng cho bước tiếp theo khi cần báo hệ thống ngoài sau provisioning thành công.

  • X-DTAA-Event

    Tên event như lead.created hoặc lead.updated.

  • X-DTAA-Signature

    Chữ ký HMAC của payload, kiểm tra bằng secret đã cấu hình.

  • X-DTAA-Delivery

    Mã delivery để retry và trace log khi endpoint lỗi.

HTHeader webhookPOST
POST /webhooks/dtaa HTTP/1.1
X-DTAA-Event: <x-dtaa-event>
X-DTAA-Signature: <x-dtaa-signature>
X-DTAA-Delivery: <x-dtaa-delivery>
Content-Type: application/json

{ "event": "lead.created", "id": "evt_01", "data": { "...": "..." } }
Admin có thể tạo endpoint platform trong phần settings; outbox worker giao sự kiện theo queue và ghi lỗi retry được.

REST API đọc dữ liệu Bearer token dùng cho API v1 đọc/ghi hiện tại; các thao tác ghi quan trọng dùng idempotency để tránh đồng bộ lặp.

MethodPathAbilityMục đích
GET/api/v1/workspace*Đọc workspace của token hiện tại.
GET/api/v1/productscatalog:readĐọc danh sách sản phẩm và biến thể.
POST/api/v1/productscatalog:writeUpsert sản phẩm và biến thể theo SKU.
GET/POST/oauth/authorizeauthorization_codeUser owner/manager duyệt consent, dùng redirect_uri allowlist và PKCE S256/plain.
POST/api/oauth/tokenclient_credentials / authorization_code / refresh_tokenĐổi client credentials, authorization code hoặc refresh token lấy Bearer token 1 giờ.
GET/api/v1/ordersorders:readĐọc danh sách đơn hàng và item.
POST/api/v1/ordersorders:writeTạo order đã thanh toán, mặc định fulfill ngay; gửi fulfill_now=false để xử lý fulfillment từng phần.
POST/api/v1/orders/{order}/fulfillmentsorders:writeTạo fulfillment từng phần, trừ tồn và idempotent theo idempotency_key.
POST/api/v1/orders/{order}/returnsorders:writeTạo phiếu trả hàng/hoàn tiền; gửi refund_provider=http để job gọi gateway HTTP đã cấu hình.

API reference nhanh Các quy ước tối thiểu để partner gọi API an toàn và idempotent.

Production endpoint

Dùng host production của workspace hoặc domain platform được cấu hình.

https://your-domain.example/api
Base URL

Bearer token

Gửi access token từ OAuth hoặc API token workspace trong header Authorization.

Authorization: Bearer <token>
Auth

Ghi dữ liệu không lặp

Các API tạo order, fulfillment và return nên gửi khóa idempotency ổn định theo hệ thống ngoài.

X-Idempotency-Key: erp-order-1001
Idempotency

Mã lỗi HTTP chuẩn

401 cho token sai, 403 cho thiếu ability, 422 cho validation và 429 khi bị throttle.

422 validation_error
Errors

Spec JSON

Tải spec máy đọc được để import vào Postman, Scalar hoặc generator SDK.

/api/openapi.json
OpenAPI

JavaScript package

Package mỏng bọc OAuth, Bearer token, idempotency key và catalog/order API hiện có.

packages/dtaa-sdk-js
SDK

SDK examples tối thiểu Đã có package JavaScript publish-ready tại packages/dtaa-sdk-js; ví dụ curl/JS bên dưới vẫn giữ request gốc để partner dễ debug.

Đổi OAuth code lấy token

Dùng authorization_code kèm PKCE verifier.

CUcurl
curl -X POST https://your-domain.example/api/oauth/token \
  -H 'Accept: application/json' \
  -d 'grant_type=authorization_code' \
  -d 'client_id=client-id' \
  -d 'client_secret=client-secret' \
  -d 'redirect_uri=https://partner.example/callback' \
  -d 'code=auth-code' \
  -d 'code_verifier=pkce-verifier'

Upsert sản phẩm theo SKU

Gửi Bearer token có ability catalog:write.

JAJavaScript
await fetch('/api/v1/products', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json',
    'X-Idempotency-Key': 'sku-SKU-001'
  },
  body: JSON.stringify({ sku: 'SKU-001', name: 'Demo item', price_cents: 120000 })
});

Dùng package SDK

SDK dùng fetch chuẩn, có thể inject fetchImpl để test offline.

JAJavaScript SDK
import { DtaaClient } from '@dtaa-tech/platform-sdk';

const client = new DtaaClient({ baseUrl: 'https://your-domain.example', accessToken: '<token>' });
await client.upsertProduct({ sku: 'SKU-001', name: 'Demo item', price_cents: 120000 }, { idempotencyKey: 'sku-SKU-001' });

Changelog API Các mốc public để partner biết phần nào đã sẵn sàng tích hợp.

  • JavaScript SDK publish-ready

    Package packages/dtaa-sdk-js có client API, helper OAuth token, type declarations và test offline bằng mock fetch.

    2026-07-15
  • OAuth consent, PKCE và refresh token

    Authorization-code flow đã có consent screen, redirect URI allowlist, PKCE và refresh token rotation.

    2026-07-15
  • Order fulfillment và return idempotent

    API fulfillment từng phần và return/refund manual đã nhận idempotency_key để tránh đồng bộ lặp.

    2026-07-15
  • Webhook/outbox foundation

    Webhook endpoint, signed headers, retry worker và retry UI được dùng cho lead và commerce event.

    2026-07-07
  • Webhook sự kiện

    Admin có thể tạo endpoint platform trong phần settings; outbox worker giao sự kiện theo queue và ghi lỗi retry được.

  • API token

    Workspace đã có API token, OAuth client credentials, authorization-code consent, PKCE và refresh token.

  • Ký request

    Webhook có secret hash và header chữ ký để hệ thống nhận kiểm tra nguồn gửi trước khi xử lý.