Bỏ qua để đến nội dung

Khoá API

~17 phút đọc

Khoá API: tạo, xoay, thu hồi, gia hạn và xem các lần gọi gần đây (không bao giờ hiện lại khoá).

MethodPathTóm tắtQuyềnNhóm tốc độTương tác
GET/v1/api-keysDanh sách khoá API của tổ chứcapikey.readreadScalar
POST/v1/api-keysTạo khoá API (bí mật chỉ trả một lần)apikey.writewriteScalar
GET/v1/api-keys/{id}Chi tiết khoá API (không bao giờ có bí mật)apikey.readreadScalar
GET/v1/api-keys/{id}/callsCác lệnh gọi mẫu gần đây của khoáapikey.readreadScalar
POST/v1/api-keys/{id}:extendDời hạn khoá (tối đa 12 tháng kể từ bây giờ; khôi phục được khoá đã hết hạn)apikey.writewriteScalar
POST/v1/api-keys/{id}:revokeThu hồi khoá (có hiệu lực trên mọi máy chủ trong vòng 5 giây)apikey.writewriteScalar
POST/v1/api-keys/{id}:rotateXoay khoá: cấp khoá thay thế, khoá cũ còn dùng 24 giờapikey.writewriteScalar

Danh sách khoá API của tổ chức

Chỉ người giữ nút gốc với phạm vi all xem được (còn lại 403 permission_denied). Phân trang theo con trỏ.

Quyền: apikey.read
  • Nhóm tốc độ: read
  • Phản hồi thành công 200: Danh sách khoá. — ApiKeyList, application/json
  • Mã lỗi riêng của endpoint: invalid_cursor
TênVị tríBắt buộcKiểuMô tả
limitqueryKhôngintegerSố phần tử mỗi trang (1–100, mặc định 20).
cursorqueryKhôngCursorCon trỏ phân trang mờ (cur_…) lấy từ next_cursor; không tự tạo hay sửa.
statequeryKhôngstring—
envqueryKhôngstringlive: dữ liệu thật; test: sandbox.
curl -sS -X GET "https://api.dongtien.pro/v1/api-keys" \
-H "Authorization: Bearer $DT_API_KEY"

Mở trong tài liệu tương tác

Tạo khoá API (bí mật chỉ trả một lần)

Cần xác thực lại gần đây. Khoá không mang scope mà người tạo không thực hiện được ở mọi công ty khoá chạm tới (403 permission_denied); công ty hoặc tài khoản ngoài phạm vi → 404. Được ghi nhật ký kiểm toán apikey.create.

Quyền: apikey.write Cần xác thực lại gần đây
  • Nhóm tốc độ: write
  • Nội dung yêu cầu: CreateApiKey (application/json, bắt buộc)
  • Phản hồi thành công 201: Khoá vừa tạo (kèm bí mật). — ApiKeyIssued, application/json
  • Mã lỗi riêng của endpoint: step_up_required, conflict
curl -sS -X POST "https://api.dongtien.pro/v1/api-keys" \
-H "Authorization: Bearer $DT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Đồng bộ kế toán",
"env": "live",
"scopes": [
"transactions:read",
"accounts:read"
],
"all_companies": true,
"ip_allowlist": [
"203.0.113.0/24"
],
"expires_at": "2030-06-30T00:00:00+07:00"
}'

Mở trong tài liệu tương tác

Chi tiết khoá API (không bao giờ có bí mật)

Quyền: apikey.read
  • Nhóm tốc độ: read
  • Phản hồi thành công 200: Khoá. — ApiKey, application/json
  • Mã lỗi riêng của endpoint: resource_not_found
TênVị tríBắt buộcKiểuMô tả
idpathCóApiKeyIdMã khoá API (apk_…).
curl -sS -X GET "https://api.dongtien.pro/v1/api-keys/$ID" \
-H "Authorization: Bearer $DT_API_KEY"

Mở trong tài liệu tương tác

Các lệnh gọi mẫu gần đây của khoá

Phương thức, đường dẫn, mã trạng thái (không có nội dung). Tối đa 50 lệnh gần nhất, không phân trang.

Quyền: apikey.read
  • Nhóm tốc độ: read
  • Phản hồi thành công 200: Các lệnh gọi. — ApiKeyCallList, application/json
  • Mã lỗi riêng của endpoint: resource_not_found
TênVị tríBắt buộcKiểuMô tả
idpathCóApiKeyIdMã khoá API (apk_…).
limitqueryKhônginteger—
curl -sS -X GET "https://api.dongtien.pro/v1/api-keys/$ID/calls" \
-H "Authorization: Bearer $DT_API_KEY"

Mở trong tài liệu tương tác

Dời hạn khoá (tối đa 12 tháng kể từ bây giờ; khôi phục được khoá đã hết hạn)

Cần xác thực lại gần đây. Khoá đã thu hồi mãi mãi bị thu hồi (409 conflict). Được ghi nhật ký kiểm toán apikey.extend.

Quyền: apikey.write Cần xác thực lại gần đây
  • Nhóm tốc độ: write
  • Nội dung yêu cầu: ExtendApiKey (application/json, bắt buộc)
  • Phản hồi thành công 200: Khoá sau khi dời hạn. — ApiKey, application/json
  • Mã lỗi riêng của endpoint: step_up_required, resource_not_found, conflict
TênVị tríBắt buộcKiểuMô tả
idpathCóApiKeyIdMã khoá API (apk_…).
curl -sS -X POST "https://api.dongtien.pro/v1/api-keys/$ID:extend" \
-H "Authorization: Bearer $DT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"expires_at": "2030-06-30T00:00:00+07:00"
}'

Mở trong tài liệu tương tác

Thu hồi khoá (có hiệu lực trên mọi máy chủ trong vòng 5 giây)

Cần xác thực lại gần đây. Khoá đã thu hồi → 409 conflict. Thu hồi khoá thay thế trong thời gian ân hạn cũng thu hồi khoá tiền nhiệm. Được ghi nhật ký kiểm toán apikey.revoke.

Quyền: apikey.write Cần xác thực lại gần đây
  • Nhóm tốc độ: write
  • Nội dung yêu cầu: RevokeApiKey (application/json)
  • Phản hồi thành công 200: Khoá đã thu hồi. — ApiKey, application/json
  • Mã lỗi riêng của endpoint: step_up_required, resource_not_found, conflict
TênVị tríBắt buộcKiểuMô tả
idpathCóApiKeyIdMã khoá API (apk_…).
curl -sS -X POST "https://api.dongtien.pro/v1/api-keys/$ID:revoke" \
-H "Authorization: Bearer $DT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"reason": "Khoá bị lộ trong kho mã nguồn."
}'

Mở trong tài liệu tương tác

Xoay khoá: cấp khoá thay thế, khoá cũ còn dùng 24 giờ

Cần xác thực lại gần đây. Chỉ xoay được khoá đang active (còn lại 409 conflict); người xoay phải có khả năng cấp mọi scope của khoá cũ. Được ghi nhật ký kiểm toán apikey.rotate; phản hồi có Cache-Control: no-store.

Quyền: apikey.write Cần xác thực lại gần đây
  • Nhóm tốc độ: write
  • Nội dung yêu cầu: RotateApiKey (application/json)
  • Phản hồi thành công 200: Khoá thay thế và khoá cũ. — RotatedApiKey, application/json
  • Mã lỗi riêng của endpoint: step_up_required, resource_not_found, conflict
TênVị tríBắt buộcKiểuMô tả
idpathCóApiKeyIdMã khoá API (apk_…).
curl -sS -X POST "https://api.dongtien.pro/v1/api-keys/$ID:rotate" \
-H "Authorization: Bearer $DT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Đồng bộ kế toán (xoay quý 3)",
"expires_at": "2030-06-30T00:00:00+07:00"
}'

Mở trong tài liệu tương tác

TrườngKiểuBắt buộcMô tả
dataApiKey[]Có—
data[].all_companiesbooleanCóMọi công ty của tổ chức (kể cả công ty thêm sau), trừ công ty cô lập cứng.
data[].bank_account_idsAccountId[] | nullCóChỉ các tài khoản này; null = mọi tài khoản của công ty khoá chạm tới.
data[].company_idsOrgId[]CóCông ty khoá được dùng; rỗng khi all_companies.
data[].created_atTimestampCó—
data[].created_byUserIdCó—
data[].displaystringCódt_live_ + vài ký tự đầu + •••• + 4 ký tự cuối: phần duy nhất được hiện lại.
data[].envstringCólive: dữ liệu thật; test: sandbox. Giá trị: live, test.
data[].expires_atTimestamp | nullCó—
data[].extended_atTimestamp | nullCó—
data[].grace_untilstring | nullCóKhoá cũ vẫn dùng được đến thời điểm này sau khi xoay.
data[].idApiKeyIdCó—
data[].ip_allowliststring[]CóĐịa chỉ IPv4/IPv6 hoặc CIDR được phép; rỗng = không giới hạn.
data[].last4stringCó—
data[].last_used_atTimestamp | nullCó—
data[].last_used_ipstring | nullCó—
data[].namestringCó—
data[].pinned_versionstring | nullCóPhiên bản API (YYYY-MM-DD) khoá được ghim.
data[].revoked_atTimestamp | nullCó—
data[].revoked_reasonstring | nullCó—
data[].rotated_from_idstring | nullCóKhoá tiền nhiệm khi đây là khoá thay thế sau :rotate.
data[].scopesstring[]CóCác scope khoá mang (xem danh mục scope).
data[].startstringCó—
data[].statestringCóGiá trị: active, revoked, expired.
has_morebooleanCó—
next_cursorstring | nullCóCon trỏ trang kế; null khi hết dữ liệu.
objectstringCóGiá trị: list.
TrườngKiểuBắt buộcMô tả
all_companiesbooleanKhôngMọi công ty của tổ chức (kể cả công ty thêm sau), trừ công ty cô lập cứng.
bank_account_idsAccountId[]KhôngGiới hạn theo tài khoản; bỏ trống = mọi tài khoản của các công ty được chọn.
company_idsOrgId[]KhôngCần khi all_companies=false.
envstringCólive: dữ liệu thật; test: sandbox. Giá trị: live, test.
expires_atstring (date-time)KhôngBắt buộc với khoá live; tối đa 12 tháng kể từ bây giờ.
ip_allowliststring[]KhôngĐịa chỉ IPv4/IPv6 hoặc CIDR; giá trị sai → 422.
namestringCó—
pinned_versionstringKhôngPhiên bản API YYYY-MM-DD để ghim.
scopesstring[]CóGiá trị: transactions:read, accounts:read, balances:read, invoices:read, counterparties:read, cashflow:read, settlement:read, export:read, audit:read, mcp:read, collect:write, reconcile:propose, import:write, webhooks:write, integrations:write, collect:read, integrations:read, billing:read.
TrườngKiểuBắt buộcMô tả
all_companiesbooleanCóMọi công ty của tổ chức (kể cả công ty thêm sau), trừ công ty cô lập cứng.
bank_account_idsAccountId[] | nullCóChỉ các tài khoản này; null = mọi tài khoản của công ty khoá chạm tới.
company_idsOrgId[]CóCông ty khoá được dùng; rỗng khi all_companies.
created_atTimestampCó—
created_byUserIdCó—
displaystringCódt_live_ + vài ký tự đầu + •••• + 4 ký tự cuối: phần duy nhất được hiện lại.
envstringCólive: dữ liệu thật; test: sandbox. Giá trị: live, test.
expires_atTimestamp | nullCó—
extended_atTimestamp | nullCó—
grace_untilstring | nullCóKhoá cũ vẫn dùng được đến thời điểm này sau khi xoay.
idApiKeyIdCó—
ip_allowliststring[]CóĐịa chỉ IPv4/IPv6 hoặc CIDR được phép; rỗng = không giới hạn.
keystringCóKhoá đầy đủ, chỉ hiện một lần. Hãy lưu ngay: không thể lấy lại.
last4stringCó—
last_used_atTimestamp | nullCó—
last_used_ipstring | nullCó—
namestringCó—
pinned_versionstring | nullCóPhiên bản API (YYYY-MM-DD) khoá được ghim.
revoked_atTimestamp | nullCó—
revoked_reasonstring | nullCó—
rotated_from_idstring | nullCóKhoá tiền nhiệm khi đây là khoá thay thế sau :rotate.
scopesstring[]CóCác scope khoá mang (xem danh mục scope).
startstringCó—
statestringCóGiá trị: active, revoked, expired.
TrườngKiểuBắt buộcMô tả
all_companiesbooleanCóMọi công ty của tổ chức (kể cả công ty thêm sau), trừ công ty cô lập cứng.
bank_account_idsAccountId[] | nullCóChỉ các tài khoản này; null = mọi tài khoản của công ty khoá chạm tới.
company_idsOrgId[]CóCông ty khoá được dùng; rỗng khi all_companies.
created_atTimestampCó—
created_byUserIdCó—
displaystringCódt_live_ + vài ký tự đầu + •••• + 4 ký tự cuối: phần duy nhất được hiện lại.
envstringCólive: dữ liệu thật; test: sandbox. Giá trị: live, test.
expires_atTimestamp | nullCó—
extended_atTimestamp | nullCó—
grace_untilstring | nullCóKhoá cũ vẫn dùng được đến thời điểm này sau khi xoay.
idApiKeyIdCó—
ip_allowliststring[]CóĐịa chỉ IPv4/IPv6 hoặc CIDR được phép; rỗng = không giới hạn.
last4stringCó—
last_used_atTimestamp | nullCó—
last_used_ipstring | nullCó—
namestringCó—
pinned_versionstring | nullCóPhiên bản API (YYYY-MM-DD) khoá được ghim.
revoked_atTimestamp | nullCó—
revoked_reasonstring | nullCó—
rotated_from_idstring | nullCóKhoá tiền nhiệm khi đây là khoá thay thế sau :rotate.
scopesstring[]CóCác scope khoá mang (xem danh mục scope).
startstringCó—
statestringCóGiá trị: active, revoked, expired.
TrườngKiểuBắt buộcMô tả
dataApiKeyCall[]Có—
data[].atTimestampCó—
data[].ipstring | nullCó—
data[].methodstringCó—
data[].msintegerCóThời gian xử lý (mili giây).
data[].pathstringCó—
data[].statusintegerCó—
has_morebooleanCóGiá trị: false.
next_cursorany | nullCó—
objectstringCóGiá trị: list.
TrườngKiểuBắt buộcMô tả
expires_atstring (date-time)Có—
TrườngKiểuBắt buộcMô tả
reasonstringKhông—
TrườngKiểuBắt buộcMô tả
expires_atstring (date-time)Không—
namestringKhông—
TrườngKiểuBắt buộcMô tả
keyApiKeyIssuedCó—
key.all_companiesbooleanCóMọi công ty của tổ chức (kể cả công ty thêm sau), trừ công ty cô lập cứng.
key.bank_account_idsAccountId[] | nullCóChỉ các tài khoản này; null = mọi tài khoản của công ty khoá chạm tới.
key.company_idsOrgId[]CóCông ty khoá được dùng; rỗng khi all_companies.
key.created_atTimestampCó—
key.created_byUserIdCó—
key.displaystringCódt_live_ + vài ký tự đầu + •••• + 4 ký tự cuối: phần duy nhất được hiện lại.
key.envstringCólive: dữ liệu thật; test: sandbox. Giá trị: live, test.
key.expires_atTimestamp | nullCó—
key.extended_atTimestamp | nullCó—
key.grace_untilstring | nullCóKhoá cũ vẫn dùng được đến thời điểm này sau khi xoay.
key.idApiKeyIdCó—
key.ip_allowliststring[]CóĐịa chỉ IPv4/IPv6 hoặc CIDR được phép; rỗng = không giới hạn.
key.keystringCóKhoá đầy đủ, chỉ hiện một lần. Hãy lưu ngay: không thể lấy lại.
key.last4stringCó—
key.last_used_atTimestamp | nullCó—
key.last_used_ipstring | nullCó—
key.namestringCó—
key.pinned_versionstring | nullCóPhiên bản API (YYYY-MM-DD) khoá được ghim.
key.revoked_atTimestamp | nullCó—
key.revoked_reasonstring | nullCó—
key.rotated_from_idstring | nullCóKhoá tiền nhiệm khi đây là khoá thay thế sau :rotate.
key.scopesstring[]CóCác scope khoá mang (xem danh mục scope).
key.startstringCó—
key.statestringCóGiá trị: active, revoked, expired.
old_keyApiKeyCó—
old_key.all_companiesbooleanCóMọi công ty của tổ chức (kể cả công ty thêm sau), trừ công ty cô lập cứng.
old_key.bank_account_idsAccountId[] | nullCóChỉ các tài khoản này; null = mọi tài khoản của công ty khoá chạm tới.
old_key.company_idsOrgId[]CóCông ty khoá được dùng; rỗng khi all_companies.
old_key.created_atTimestampCó—
old_key.created_byUserIdCó—
old_key.displaystringCódt_live_ + vài ký tự đầu + •••• + 4 ký tự cuối: phần duy nhất được hiện lại.
old_key.envstringCólive: dữ liệu thật; test: sandbox. Giá trị: live, test.
old_key.expires_atTimestamp | nullCó—
old_key.extended_atTimestamp | nullCó—
old_key.grace_untilstring | nullCóKhoá cũ vẫn dùng được đến thời điểm này sau khi xoay.
old_key.idApiKeyIdCó—
old_key.ip_allowliststring[]CóĐịa chỉ IPv4/IPv6 hoặc CIDR được phép; rỗng = không giới hạn.
old_key.last4stringCó—
old_key.last_used_atTimestamp | nullCó—
old_key.last_used_ipstring | nullCó—
old_key.namestringCó—
old_key.pinned_versionstring | nullCóPhiên bản API (YYYY-MM-DD) khoá được ghim.
old_key.revoked_atTimestamp | nullCó—
old_key.revoked_reasonstring | nullCó—
old_key.rotated_from_idstring | nullCóKhoá tiền nhiệm khi đây là khoá thay thế sau :rotate.
old_key.scopesstring[]CóCác scope khoá mang (xem danh mục scope).
old_key.startstringCó—
old_key.statestringCóGiá trị: active, revoked, expired.