API 整合

API 整合的技術規範。

1. Base URL

您的端點 URL 顯示在端點詳情頁上。

POST GET (list)
https://api.3minapi.com/api/v1/data/{slug}
GET (search)
https://api.3minapi.com/api/v1/data/{slug}/search
GET (poll)
https://api.3minapi.com/api/v1/data/{slug}/poll
GET / PUT / DELETE
https://api.3minapi.com/api/v1/data/{slug}/{record_id}

2. 身份認證

在請求頭中包含您的 API 金鑰。

請求頭描述是否必填
AuthorizationBearer tm_test_xxx... / Bearer tm_live_xxx...Yes
Content-Typeapplication/jsonYes
X-Webhook-CallbackWebhook URLNo
X-Webhook-Auth認證值(例如 Bearer token)No
X-Webhook-Auth-Header認證頭名稱No

3. 請求格式

  • Content-Type: 僅支援 application/json
  • 最大大小: 每次請求 100KB
  • 方法: POST / GET(單筆 + 清單 + 搜尋 + 輪詢) / PUT / DELETE

CRUD 端點

每個端點自動支援以下 HTTP 方法:

方法路徑描述
POST/api/v1/data/{slug}建立新記錄(非同步,加入佇列)
GET/api/v1/data/{slug}/{record_id}按 ID 查詢記錄
GET/api/v1/data/{slug}取得最近記錄清單(cursor 分頁,每頁預設 10 筆 / 最多 30 筆)
GET/api/v1/data/{slug}/search依 payload 文字搜尋記錄(q 必填,時間範圍選用 — 預設最近 30 天,游標分頁)
GET/api/v1/data/{slug}/poll取得上次輪詢之後建立的記錄,由舊到新(游標分頁,預設 100 / 每頁最多 100)
PUT/api/v1/data/{slug}/{record_id}按 ID 替換記錄(非同步,加入佇列)
DELETE/api/v1/data/{slug}/{record_id}按 ID 刪除記錄(非同步,加入佇列)

GET(單筆)、PUT、DELETE 需要使用之前 POST 回應中返回的記錄 ID。GET(清單)、GET(搜尋)和 GET(輪詢)不需要記錄 ID。

POST — 建立:

curl -X POST https://api.3minapi.com/api/v1/data/{slug} \
  -H "Authorization: Bearer tm_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
  "order_id": "ORD-2024-001",
  "amount": 45000,
  "items": ["Item A", "Item B"],
  "paid": true
}'

GET — 讀取:

curl https://api.3minapi.com/api/v1/data/{slug}/rec_abc123 \
  -H "Authorization: Bearer tm_test_xxx"

GET — 清單:

curl "https://api.3minapi.com/api/v1/data/{slug}?limit=10" \
  -H "Authorization: Bearer tm_test_xxx"

# Next page — pass the next_cursor returned in the previous response
curl "https://api.3minapi.com/api/v1/data/{slug}?limit=10&cursor=<next_cursor>" \
  -H "Authorization: Bearer tm_test_xxx"

GET — 搜尋:

# q is required (min 3 chars). start/end are optional — defaults to last 30 days.
curl "https://api.3minapi.com/api/v1/data/{slug}/search?q=keyword&limit=10" \
  -H "Authorization: Bearer tm_test_xxx"

# Next page — pass the next_cursor returned in the previous response
curl "https://api.3minapi.com/api/v1/data/{slug}/search?q=keyword&limit=10&cursor=<next_cursor>" \
  -H "Authorization: Bearer tm_test_xxx"

GET — 輪詢:

# First call — no cursor. Subscribes from now on.
# Use ?since=2026-08-01T00:00:00Z (or 2026-08-01) to start from a point in time — always UTC.
curl "https://api.3minapi.com/api/v1/data/{slug}/poll?limit=100" \
  -H "Authorization: Bearer tm_test_xxx"

# Every response carries exactly one of two cursors:
#   next_cursor — a backlog remains. Call again right away with it.
#   poll_cursor — you are caught up. Save it and wait for the next cycle.
# The newest ~60 seconds are held back until the queue catches up, so those
# records arrive on a later poll instead of being skipped.

# The whole loop:
CURSOR=""
while true; do
  CODE=$(curl -s -o /tmp/poll.json -w '%{http_code}' \
    "https://api.3minapi.com/api/v1/data/{slug}/poll?limit=100&cursor=$CURSOR" \
    -H "Authorization: Bearer tm_test_xxx")

  # On any error, keep the cursor and retry. Overwriting it would lose your place.
  if [ "$CODE" != "200" ]; then
    echo "poll failed with HTTP $CODE" >&2
    sleep 60
    continue
  fi

  jq -c '.data[]' /tmp/poll.json   # oldest first — dedupe on id, retries can repeat a record

  NEXT=$(jq -r '.pagination.next_cursor // empty' /tmp/poll.json)
  if [ -n "$NEXT" ]; then CURSOR=$NEXT; continue; fi   # more waiting — no sleep

  POLL=$(jq -r '.pagination.poll_cursor // empty' /tmp/poll.json)
  if [ -n "$POLL" ]; then CURSOR=$POLL; fi             # caught up — save and wait
  sleep 60
done

PUT — 更新:

curl -X PUT https://api.3minapi.com/api/v1/data/{slug}/rec_abc123 \
  -H "Authorization: Bearer tm_test_xxx" \
  -H "Content-Type: application/json" \
  -d '{
  "order_id": "ORD-2024-001",
  "amount": 50000,
  "items": ["Item A", "Item B", "Item C"],
  "paid": true
}'

DELETE — 刪除:

curl -X DELETE https://api.3minapi.com/api/v1/data/{slug}/rec_abc123 \
  -H "Authorization: Bearer tm_test_xxx"

4. 回應格式

成功回應 (202):

{
  "success": true,
  "id": "rec_abc123",
  "message": "Request queued"
}

錯誤回應示例 (400):

{
  "success": false,
  "error": "Validation failed",
  "details": [
    { "field": "order_id", "error": "Required field is missing" }
  ]
}

錯誤回應:

CodeStatusDescription
400請求錯誤無效的 JSON 或缺少必填欄位
401未授權缺少或無效的 API 金鑰,或 API 金鑰已被所有者停用
403禁止訪問端點未啟用或訂閱已過期
415不支援的媒體類型Content-Type 必須為 application/json
429請求過多月度請求額度已用完
5xx伺服器錯誤內部伺服器錯誤(500、502、503 等)

5. 協作者 Webhook

API 協作者可以直接接收處理結果。

重試政策: 請在 15 秒內回傳 2xx。失敗後正式環境約 5 小時內共 6 次嘗試,沙箱環境約 12 分鐘內共 4 次嘗試

6. 測試工具

上線前在沙箱中測試。

  • 內置測試頁面: 在端點詳情頁點擊測試按鈕即可訪問 — 無需額外工具
  • cURL: 從命令行測試
  • Postman: 使用 API 測試工具

7. 正式控制台

部署到正式環境後,端點所有者可以直接從儀表板管理正式資料 — 無需外部 API 工具或程式碼。

訪問方式

前往端點詳情 → 正式標籤頁 → 點擊"開啟控制台"在新標籤頁開啟。

功能

  • 完整 CRUD 支援(POST / GET / PUT / DELETE)操作正式資料
  • 正式環境 API 金鑰已自動設定 — 無需手動輸入
  • 控制台的請求不會觸發 Webhook

僅限所有者

只有端點所有者可以訪問正式控制台。協作者無法使用。