เริ่มต้นใช้งาน API
ANKK Public API เป็น RESTful API สำหรับจัดการงานโซเชียลมีเดียหลายช่องทางผ่านโปรแกรม โดยใช้คีย์ API ระดับแบรนด์ (spk_...) เพียงชุดเดียว
📌 ภาพรวม Endpoint
หัวข้อที่มีชื่อว่า “📌 ภาพรวม Endpoint”- URL หลัก:
https://api.ankk.app - Swagger / เอกสารแบบโต้ตอบ:
https://api.ankk.app/v1/docs - ข้อกำหนด OpenAPI แบบ JSON:
https://api.ankk.app/v1/openapi.json
1. ตรวจสอบสถานะการทำงานของบริการ
หัวข้อที่มีชื่อว่า “1. ตรวจสอบสถานะการทำงานของบริการ”Endpoint ตรวจสอบสถานะไม่ต้องใช้ส่วนหัวการยืนยันตัวตน
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 ไปใช้งาน
# 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;if (!API_KEY) throw new Error('Set ANKK_API_KEY');const BASE_URL = 'https://api.ankk.app/v1';
const res = await fetch(`${BASE_URL}/brand/connections`, { headers: { Authorization: `Bearer ${API_KEY}` }});if (!res.ok) throw new Error(`Connections request failed: ${res.status}`);const { items: connections } = await res.json();console.log('Connected accounts:', connections);const targetConnectionId = connections[0]?.connection_id;if (!targetConnectionId) throw new Error('Connect an SNS account first');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)response.raise_for_status()connections = response.json().get('items', [])print(f'Connected accounts: {connections}')target_connection_id = connections[0]['connection_id'] if connections else Noneif not target_connection_id: raise RuntimeError('Connect an SNS account first')4. เผยแพร่เนื้อหาแรกของคุณ
หัวข้อที่มีชื่อว่า “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
หัวข้อที่มีชื่อว่า “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: 'my-first-post-001', text: 'Hello World from TypeScript! 🚀' })});
if (publishRes.status !== 202) throw new Error(`Publish request failed: ${publishRes.status}`);const result = await publishRes.json();console.log('Publish accepted (HTTP 202):', result);payload = { 'connection_id': target_connection_id, 'idempotency_key': 'my-first-post-001', 'text': 'Hello World from Python! 🚀',}
publish_res = requests.post( f'{BASE_URL}/brand/contents', headers={**headers, 'Content-Type': 'application/json'}, json=payload,)publish_res.raise_for_status()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"