報表 API
此內容適用於 5.0 (Preview)。 切換至 4.5(目前版本) 以查看目前正式版文件。
報表 API 由 Cube.js 提供支援,具備高效能查詢、預聚合快取與權限控制。您可以透過 REST API 或任何官方支援的前端套件(如 React、Vue 或 WebSockets)進行查詢。更多整合方式請參閱 Cube 前端整合文件。
REST API
Section titled “REST API”請求基礎網址
Section titled “請求基礎網址”https://reporting.qpos.me/cubejs-api/v1請先依前一個章節取得 access_token,並於每次請求的 Header 中附帶 Authorization: Bearer {access_token}。
請求可帶入 query 參數,API 會自動將查詢轉換為 SQL 並回傳對應的 JSON 結果。
查詢所有訂單總數的簡易範例:
curl --request GET 'https://reporting.qpos.me/cubejs-api/v1/load?query={"measures":["orders.count"]}' \--header 'Authorization: Bearer eyJhbGciOi...'{ "data": [ { "orders.count": 19461 } ], "query": { ... }}中繼資料 (Metadata)
Section titled “中繼資料 (Metadata)”取得所有可用的 Cubes、Dimensions(維度)與 Measures(指標)清單:
https://reporting.qpos.me/cubejs-api/v1/metaQUEUE 報表 API 預設以 UTC 時區進行查詢與回傳,您可以在 query 中加入 timezone 參數指定時區(例如 Asia/Taipei):
curl --request GET 'https://reporting.qpos.me/cubejs-api/v1/load?query={"timezone": "Asia/Taipei", "measures":["orders.count"]}' \--header 'Authorization: Bearer eyJhbGciOi...'常用查詢範例
Section titled “常用查詢範例”取得訂單清單
Section titled “取得訂單清單”curl --request GET 'https://reporting.qpos.me/cubejs-api/v1/load?query={"dimensions": ["orders.paid_at", "orders.status", "orders.amount"], "limit": 2, "order": [["orders.paid_at", "desc"]]}' \--header 'Authorization: Bearer eyJhbGciOiJSUz...' \--header 'Content-Type: application/x-www-form-urlencoded'{ "data": [ { "orders.paid_at": "2023-10-18T02:37:01.234", "orders.status": "paid", "orders.amount": 150 }, { "orders.paid_at": "2023-09-01T04:46:30.896", "orders.status": "paid", "orders.amount": 180 } ], "query": { ... }}依日期區間查詢訂單商品明細與數量
Section titled “依日期區間查詢訂單商品明細與數量”curl --request GET 'https://reporting.qpos.me/cubejs-api/v1/load?query={"dimensions": ["orders.id", "orders.paid_at", "orders.status", "orders.amount","menu_products.name", "menu_variants.name", "line_items.quantity"], "filters": [{"member": "orders.paid_at", "operator": "inDateRange", "values": ["2023-10-01", "2023-11-01"] }], "order": [["orders.paid_at", "asc"]], "limit": 3}' \--header 'Authorization: Bearer eyJhbGciOi...'{ "data": [ { "orders.id": "4WGOlrQUA9Tq8-HA6cGBtC", "orders.paid_at": "2023-10-18T02:37:01.234", "orders.status": "paid", "orders.amount": 150, "menu_products.name": "Coffee", "menu_variants.name": "Large", "line_items.quantity": 1 } ], "query": { ... }}