REST API
Mọi thao tác trong giao diện Celerp đều là một REST endpoint - đúng API mà giao diện dùng bên trong. Tự động hóa quy trình, kết nối hệ thống khác, hoặc tự xây công cụ của riêng bạn. API chạy cục bộ trên dữ liệu của bạn; không có gì được gửi lên đám mây.
🔗 URL cơ sở
http://localhost:8000 khi cài bằng pip. Ứng dụng máy tính tự chọn cổng: xem celerp-data/api-port.
🔑 Xác thực
Bearer JWT từ /auth/login
📦 Định dạng
JSON vào, JSON ra
📖 Đặc tả
GET /openapi.json (OpenAPI 3.1)
Dùng cổng nào? Khi cài bằng pip install celerp, máy chủ API chạy trên localhost:8000 (thay đổi bằng --api-port) và cổng 8080 là giao diện web cho người dùng, không phải API. Ứng dụng máy tính chọn cổng trống mỗi lần khởi động và ghi cổng API vào tệp api-port trong thư mục celerp-data. Để cố định cổng, hãy đặt CELERP_API_PORT trước khi khởi chạy.
Xác thực
Celerp sử dụng JSON Web Tokens có thời hạn ngắn. Đăng nhập bằng email và mật khẩu Celerp của bạn để nhận access token, sau đó gửi nó dưới dạng tiêu đề Bearer trong mỗi yêu cầu.
1. Đăng nhập
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "your-password"}'
Phản hồi chứa hai token:
{
"access_token": "eyJhbGciOiJI...",
"refresh_token": "eyJhbGciOiJI..."
}
2. Gọi API với token
curl http://localhost:8000/items \
-H "Authorization: Bearer eyJhbGciOiJI..."
- Token xác định người dùng, vai trò và công ty của bạn, vì vậy các yêu cầu tự động được giới hạn trong công ty đó - không cần tiêu đề thêm.
- Access token có hiệu lực tối đa 24 giờ. Khi hết hạn, nhận cặp mới bằng cách POST
refresh_tokenđến/auth/token/refresh. - Thuộc nhiều hơn một công ty? Liệt kê chúng bằng
GET /auth/my-companies, sau đó nhận token cho công ty khác bằngPOST /auth/switch-company/{company_id}.
Token mang theo quyền của bạn. Token viewer chỉ đọc được, không ghi được; dữ liệu chi phí cần vai trò manager trở lên. Xử lý token như mật khẩu - bất kỳ ai giữ token đều có thể hành động như bạn.
Thực hiện yêu cầu
Tất cả endpoint nằm dưới địa chỉ máy chủ API của bạn (http://localhost:8000 với bản cài bằng pip, như trong các ví dụ bên dưới) và trả về JSON. Endpoint danh sách trả về mảng items và số đếm total:
curl "http://localhost:8000/items?limit=20&offset=0" \
-H "Authorization: Bearer $TOKEN"
{
"items": [
{ "id": "item:...", "sku": "WIDGET-001", "name": "Widget", "quantity": 42 }
],
"total": 142
}
Phân trang: truyền ?limit= (mặc định 50) và ?offset=. Hầu hết endpoint danh sách cũng chấp nhận từ khóa tìm kiếm q= và bộ lọc cột (ví dụ: ?status=available).
Tạo dữ liệu
POST JSON để tạo bản ghi. Thao tác ghi trả về id của thực thể mới (và event_id bên dưới - mọi thay đổi trong Celerp đều là một sự kiện).
curl -X POST http://localhost:8000/crm/contacts \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Acme Corp",
"email": "[email protected]",
"contact_type": "customer",
"idempotency_key": "acme-2026-06-21"
}'
Idempotency: bao gồm idempotency_key trong bất kỳ thao tác ghi nào. Yêu cầu thử lại với cùng khóa sẽ không tạo bản ghi trùng lặp - an toàn cho mạng không ổn định và tác vụ hàng loạt.
Quy ước
- Lỗi phản hồi không phải 2xx trả về
{"detail": "..."}kèm mã trạng thái HTTP chuẩn. - Giới hạn tốc độ 60 yêu cầu/phút mỗi IP theo mặc định; đăng nhập bị giới hạn ở 10/phút. Vượt giới hạn trả về
429. - Quyền hạn endpoint được kiểm soát bởi vai trò của bạn:
viewer → operator → manager → admin → owner. - Phạm vi công ty mọi yêu cầu đều tác động đến công ty trong token của bạn; chuyển công ty để tác động đến công ty khác.
Endpoints phổ biến
Một mẫu nhỏ để bắt đầu. Mỗi module thêm endpoint của riêng nó - danh sách đầy đủ trong lược đồ OpenAPI bên dưới.
| Phương thức | Đường dẫn | Mô tả |
|---|---|---|
POST | /auth/login | Lấy access token (không cần xác thực) |
GET | /health | Trạng thái dịch vụ (không cần xác thực) |
GET | /items | Liệt kê mặt hàng tồn kho |
POST | /items | Tạo một mặt hàng |
GET | /docs | Liệt kê chứng từ (hóa đơn bán, PO, hóa đơn mua, …) |
POST | /docs | Tạo một tài liệu |
GET | /crm/contacts | Liệt kê khách hàng và nhà cung cấp |
POST | /crm/contacts | Tạo một danh bạ |
GET | /dashboard/kpis | KPI kinh doanh |
Tài liệu tham chiếu đầy đủ theo từng khu vực
Mọi endpoint mà API đang chạy cung cấp, được nhóm theo khu vực. Mỗi trang liệt kê method, path, tham số, cấu trúc request và response, cùng một ví dụ gọi.
Auth
Authentication API for Celerp users, login, logout, password recovery, company switching, and API access. (13 endpoints)
Companies
Company settings and administration API for users, roles, locations, taxes, payment terms, price lists, modules, and company preferences. (70 endpoints)
Items
Inventory API for products and stock items, quantities, pricing, locations, barcodes, valuation, imports, reservations, transfers, transformations, and stock status. (39 endpoints)
Docs
Business document API for invoices, bills, purchase orders, quotations, credit notes, shipping documents, payments, fulfillment, PDF output, and document lifecycle operations. (52 endpoints)
Lists
Inventory list API for stock audits, transfers, write-offs, manifests, scans, reservations, notes, exports, and list lifecycle operations. (38 endpoints)
Accounting
Celerp accounting REST API for the chart of accounts, journal entries, general ledger, bank reconciliation, financial statements, transfers, and fiscal period controls. (59 endpoints)
Ledger
Event ledger API for reading Celerp business events and rebuilding derived application data. (3 endpoints)
Reports
ERP reporting API for accounts receivable and payable aging, sales, purchases, and expiring inventory. (5 endpoints)
Manufacturing
Manufacturing API for production orders, recipes, work centers, workflows, material requirements, costing, scheduling, component issue, and finished-goods receipt. (32 endpoints)
Labels
Inventory label and barcode API for label templates, single-item labels, bulk label sheets, and printable PDFs. (7 endpoints)
Crm
CRM REST API for customers, suppliers, contacts, addresses, people, notes, tags, files, imports, exports, and contact management. (25 endpoints)
Subscriptions
Recurring document and subscription API for invoice and purchase-order templates, scheduling, activation, pausing, resuming, cancellation, and on-demand generation. (6 endpoints)
Connectors
Integration API for connecting Celerp ERP to external commerce and business platforms, managing connector credentials, and running data synchronization. (9 endpoints)
Payments
Payment integration API for connecting payment processing, checking payment availability, and reading connection status. (7 endpoints)
Backup
Backup and restore API for exporting, importing, listing, creating, and restoring Celerp ERP backups. (8 endpoints)
Notifications
User notification API for listing notifications and marking individual or all notifications as read. (3 endpoints)
Events
Real-time server-sent events API for Celerp notifications and live application events. (1 endpoint)
System
System health, readiness, restart, and factory reset endpoints for a Celerp ERP installation. (10 endpoints)
Admin
Administrative diagnostics and system status endpoints for maintaining a Celerp ERP installation. (2 endpoints)
Ai
Celerp AI API for ERP assistant conversations, document extraction, batch jobs, memory, usage, and user-confirmed business actions. (22 endpoints)
Attachments
Inventory attachment API for uploading, downloading, tagging, previewing, and deleting item files and product images. (12 endpoints)
Dashboard
Dashboard API for ERP KPIs, recent business activity, and searchable activity history. (3 endpoints)
Payments Public
Public payment endpoints for customer payment links and payment-provider return handling. (2 endpoints)
Received
Received documents API for documents other Celerp users shared with you: list and review them, book one as your own draft, and bring a booked draft up to date with the sender's latest revision. (5 endpoints)
Search
Global Celerp ERP search API for finding permitted records across modules from a single query. (1 endpoint)
Settings
System settings and Celerp Connect API for account setup, cloud connection state, billing, backups, connectors, and partner configuration. (17 endpoints)
Share
Document sharing API for creating, inspecting, updating, and revoking public share links for Celerp documents and lists. (4 endpoints)
Share Public
Public document sharing and import endpoints for viewing shared Celerp documents and downloading or importing portable document bundles. (4 endpoints)
Stars
Supporter badge and Celerp community recognition API for badge verification, display, opt-out, and prompts. (6 endpoints)
Verticals
Industry preset and category schema API for configuring Celerp ERP fields and defaults by business vertical. (5 endpoints)
Company Backups
16 endpoints
Migrations
22 endpoints
Khám phá toàn bộ API
Tài liệu tham chiếu đầy đủ và luôn cập nhật là lược đồ OpenAPI 3.1 do chính instance của bạn tạo ra:
GET http://localhost:8000/openapi.json
Nạp nó vào bất kỳ công cụ OpenAPI nào - Postman, Insomnia, Swagger UI hay một trình sinh client - để duyệt mọi endpoint và model, thử gửi yêu cầu và sinh client có kiểu trong ngôn ngữ của bạn. Celerp cung cấp thẳng lược đồ thay vì một trang tài liệu đặt trên máy chủ của chúng tôi, nên bề mặt API của bạn vẫn riêng tư trong instance của bạn.
Muốn dùng ngôn ngữ tự nhiên? Trợ lý AI (Connect) gọi chính API này thay bạn - chỉ cần yêu cầu nó lấy báo cáo hay tạo chứng từ bằng ngôn ngữ tự nhiên. Và nhớ rằng: mọi thứ API làm được đều không cần quyền đặc biệt nào - đúng bằng những gì một người dùng đã đăng nhập có thể làm.