API 快速入門
ANKK 公開 API 是一個 RESTful API,可讓您使用單一品牌範圍的 API 金鑰 (spk_...) 程式化地管理多通路社群媒體運作。
📌 端點概覽
섹션 제목: “📌 端點概覽”- 基礎 URL:
https://api.ankk.app - Swagger / 互動式文件:
https://api.ankk.app/v1/docs - OpenAPI JSON 規格:
https://api.ankk.app/v1/openapi.json
1. 檢查服務健康狀況
섹션 제목: “1. 檢查服務健康狀況”健康檢查端點不需要身份驗證標頭。
curl https://api.ankk.app/v1/health{ "service": "api-public", "status": "ok"}2. 取得並匯出 API 金鑰
섹션 제목: “2. 取得並匯出 API 金鑰”在網頁應用程式 (https://app.ankk.app) 中,導覽至 品牌設定 → API 金鑰 以生成金鑰,然後將其匯出:
export ANKK_API_KEY='spk_live_xxxxxxxxxxxxxxxx'3. 檢索品牌與 SNS 連線
섹션 제목: “3. 檢索品牌與 SNS 連線”檢查品牌狀態並列出已連線的 SNS 帳號,以取得目標 connection_id。
cURL
섹션 제목: “cURL”# 1. Inspect brand detailscurl https://api.ankk.app/v1/brand \ -H "Authorization: Bearer $ANKK_API_KEY"
# 2. List connected SNS accountscurl https://api.ankk.app/v1/brand/connections \ -H "Authorization: Bearer $ANKK_API_KEY"TypeScript / JavaScript
섹션 제목: “TypeScript / JavaScript”const API_KEY = process.env.ANKK_API_KEY!;const BASE_URL = 'https://api.ankk.app/v1';
const res = await fetch(`${BASE_URL}/brand/connections`, { headers: { 'Authorization': `Bearer ${API_KEY}`, },});const { items: connections } = await res.json();console.log('Connected accounts:', connections);const targetConnectionId = connections[0]?.id;Python
섹션 제목: “Python”import osimport requests
API_KEY = os.environ['ANKK_API_KEY']BASE_URL = 'https://api.ankk.app/v1'
headers = {'Authorization': f'Bearer {API_KEY}'}
response = requests.get(f'{BASE_URL}/brand/connections', headers=headers)connections = response.json().get('items', [])print(f'Connected accounts: {connections}')target_connection_id = connections[0]['id']4. 發佈您的第一篇內容
섹션 제목: “4. 發佈您的第一篇內容”提交發佈請求,並附上用戶端產生的 idempotency_key,以免重複執行。
cURL
섹션 제목: “cURL”curl -X POST "https://api.ankk.app/v1/brand/contents" \ -H "Authorization: Bearer $ANKK_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "connection_id": "conn_01jm8x9k2example", "idempotency_key": "my-first-post-001", "text": "Hello World from ANKK Public API! 🚀" }'TypeScript / JavaScript
섹션 제목: “TypeScript / JavaScript”const publishRes = await fetch(`${BASE_URL}/brand/contents`, { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ connection_id: targetConnectionId, idempotency_key: `post-${Date.now()}`, text: 'Hello World from TypeScript! 🚀', }),});
const result = await publishRes.json();console.log('Publish accepted (HTTP 202):', result);Python
섹션 제목: “Python”import time
payload = { 'connection_id': target_connection_id, 'idempotency_key': f'post-{int(time.time())}', 'text': 'Hello World from Python! 🚀',}
publish_res = requests.post( f'{BASE_URL}/brand/contents', headers={**headers, 'Content-Type': 'application/json'}, json=payload,)print('Publish outcome:', publish_res.json())5. 驗證發佈狀態
섹션 제목: “5. 驗證發佈狀態”成功的請求會傳回 HTTP 202 Accepted 與 content_id。請透過下列方式確認傳送狀態:
curl https://api.ankk.app/v1/brand/contents/<content_id> \ -H "Authorization: Bearer $ANKK_API_KEY"