API クイックスタート
ANKK パブリック API は、単一のブランドスコープの API キー (spk_...) を使用して、プログラムからマルチチャネルのソーシャルメディア運用を管理できるようにする RESTful API です。
📌 エンドポイントの概要
Section titled “📌 エンドポイントの概要”- ベース URL:
https://api.ankk.app - Swagger / インタラクティブドキュメント:
https://api.ankk.app/v1/docs - OpenAPI JSON 仕様:
https://api.ankk.app/v1/openapi.json
1. サービスのヘルスチェック
Section titled “1. サービスのヘルスチェック”ヘルスチェックエンドポイントには認証ヘッダーは不要です。
curl https://api.ankk.app/v1/health{ "service": "api-public", "status": "ok"}2. API キーの取得とエクスポート
Section titled “2. API キーの取得とエクスポート”Web アプリ (https://app.ankk.app) で ブランド設定 → API キー に移動してキーを生成し、それをエクスポートします。
export ANKK_API_KEY='spk_live_xxxxxxxxxxxxxxxx'3. ブランドと SNS 接続の取得
Section titled “3. ブランドと SNS 接続の取得”ブランドのステータスを確認し、接続されている SNS アカウントを一覧表示して、対象となる connection_id を取得します。
# 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
Section titled “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
Section titled “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. 初めてのコンテンツ公開
Section titled “4. 初めてのコンテンツ公開”重複実行を避けるために、クライアントで生成した idempotency_key を指定して公開リクエストを送信します。
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
Section titled “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
Section titled “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. 公開ステータスの確認
Section titled “5. 公開ステータスの確認”リクエストが成功すると HTTP 202 Accepted と content_id が返されます。配信ステータスは以下で確認してください。
curl https://api.ankk.app/v1/brand/contents/<content_id> \ -H "Authorization: Bearer $ANKK_API_KEY"