Khởi đầu nhanh với API
ANKK Public API là một API RESTful cho phép quản lý theo chương trình các hoạt động mạng xã hội đa kênh của bạn bằng cách sử dụng một khóa API duy nhất theo phạm vi thương hiệu (spk_...).
📌 Tổng quan về endpoint
Phần tiêu đề “📌 Tổng quan về endpoint”- URL cơ sở (Base URL):
https://api.ankk.app - Swagger / Tài liệu tương tác:
https://api.ankk.app/v1/docs - Sơ đồ OpenAPI JSON:
https://api.ankk.app/v1/openapi.json
1. Kiểm tra trạng thái dịch vụ
Phần tiêu đề “1. Kiểm tra trạng thái dịch vụ”Các điểm cuối kiểm tra sức khỏe không yêu cầu tiêu đề xác thực.
curl https://api.ankk.app/v1/health{ "service": "api-public", "status": "ok"}2. Lấy & Xuất khóa API của bạn
Phần tiêu đề “2. Lấy & Xuất khóa API của bạn”Trong ứng dụng web (https://app.ankk.app), hãy điều hướng đến Cài đặt thương hiệu → Khóa API để tạo một khóa, sau đó xuất nó:
export ANKK_API_KEY='spk_live_xxxxxxxxxxxxxxxx'3. Lấy thông tin Thương hiệu & Kết nối SNS
Phần tiêu đề “3. Lấy thông tin Thương hiệu & Kết nối SNS”Kiểm tra trạng thái thương hiệu của bạn và liệt kê các tài khoản SNS đã kết nối để lấy connection_id mục tiêu.
# 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
Phần tiêu đề “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
Phần tiêu đề “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. Xuất bản nội dung đầu tiên của bạn
Phần tiêu đề “4. Xuất bản nội dung đầu tiên của bạn”Gửi một yêu cầu xuất bản với idempotency_key do khách hàng tạo để tránh việc thực thi trùng lặp.
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
Phần tiêu đề “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
Phần tiêu đề “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. Xác minh trạng thái xuất bản
Phần tiêu đề “5. Xác minh trạng thái xuất bản”Một yêu cầu thành công sẽ trả về HTTP 202 Accepted và một content_id. Hãy xác minh trạng thái phân phối qua:
curl https://api.ankk.app/v1/brand/contents/<content_id> \ -H "Authorization: Bearer $ANKK_API_KEY"