Sản phẩm không có hoa hồng / chưa được duyệt → 422 code product_not_promotable.
GET
Lấy thông tin sản phẩm affiliate
API tạo link không kèm thông tin sản phẩm — endpoint này trả tên/ảnh/giá/hoa hồng theo product_id (trong phạm vi quyền của creator). RioHub cache 24h: id đã có trả ngay, id mới/quá hạn mới gọi TikTok.
Query params:
Param
Bắt buộc
Mô tả
creator_username
Có
Username TikTok creator (đã kết nối).
product_id
Có
1 id hoặc danh sách phân tách dấu phẩy (tối đa 100).
Nguồn nội dung phát sinh đơn (passthrough). LINKSHARE = từ link chia sẻ.
content_id
string
—
ID video / live / showcase nguồn (rỗng nếu không có).
sub_id
string
—
Nhãn theo dõi bạn gắn lúc tạo link (= tag đầy đủ).
sub1…sub4
string · null
—
Tag tách theo - thành 4 vị trí (vd u27765-m178... → sub1=u27765, sub2=m178...). Vị trí trống = ""; đơn không có tag = null. Dùng lọc qua param sub1…sub4.
commission_model
string
passthrough TikTok
Mô hình hoa hồng, vd Fixed commission. Giá trị do TikTok định nghĩa.
standard_commission_rate
number
raw, ÷100 = %
Tỷ lệ HH chuẩn dạng raw int, vd 1000 = 10%.
commission_gmv
string
—
GMV dùng để tính hoa hồng (decimal chuỗi).
est_standard_commission
string
—
Hoa hồng chuẩn ước tính.
est_commission
string
—
Hoa hồng ròng ước tính của creator (gồm cả đơn pending).
actual_commission
string · null
null khi chưa đối soát
Hoa hồng thực nhận sau đối soát.
create_time
number
unix giây
Thời điểm tạo đơn.
update_time
number
unix giây
Lần cập nhật cuối.
time_created
string
Y-m-d H:i:s
create_time dạng ngày giờ.
time_delivered
string · null
Y-m-d H:i:s
Thời điểm giao hàng (null nếu chưa giao).
payment_status
string
như settlement_status
Trạng thái thanh toán gốc từ TikTok.
GET
Lấy danh sách link đã tạo
Liệt kê các link affiliate bạn đã tạo qua API (nguồn api) cho creator, kèm số đơn & hoa hồng tổng hợp theo sub_id.
Query params:
Param
Bắt buộc
Mô tả
creator_username
Có
Creator thuộc tài khoản của bạn.
sub_id
Không
Lọc theo nhãn theo dõi.
channel
Không
Lọc theo nhãn nguồn traffic.
time_start
Không
Unix giây hoặc Y-m-d H:i:s (lọc từ ngày tạo).
time_end
Không
Unix giây hoặc Y-m-d H:i:s (lọc đến, không bao gồm).
Sao chép & thay YOUR_API_KEY bằng key của bạn. creator_username tự điền creator đã kết nối của bạn (nếu có).
# 1) Tạo link affiliate
curl -X POST '__BASE__/partner/tiktok/affiliate/links' \
-H 'X-Riohub-Api-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"creator_username":"__CREATOR__","product_url":"https://vt.tiktok.com/XXXXXX/","sub_id":"fb-ads-01"}'
# 2) Lấy danh sách link đã tạo
curl '__BASE__/partner/tiktok/affiliate/links?creator_username=__CREATOR__&page=1&page_size=50' \
-H 'X-Riohub-Api-Key: YOUR_API_KEY'
# 3) Lấy đơn hàng (lọc theo order_id / settlement_status — đều tuỳ chọn)
curl '__BASE__/partner/tiktok/affiliate/orders?creator_username=__CREATOR__&order_id=579,580&settlement_status=SETTLED&page=1&page_size=50' \
-H 'X-Riohub-Api-Key: YOUR_API_KEY'
# 4) Lấy thông tin sản phẩm affiliate
curl '__BASE__/partner/tiktok/affiliate/products?creator_username=__CREATOR__&product_id=1729...,1730...' \
-H 'X-Riohub-Api-Key: YOUR_API_KEY'
<?php
$base = '__BASE__';
$key = 'YOUR_API_KEY';
// 1) Tạo link affiliate
$ch = curl_init("$base/partner/tiktok/affiliate/links");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ["X-Riohub-Api-Key: $key", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode([
"creator_username" => "__CREATOR__",
"product_url" => "https://vt.tiktok.com/XXXXXX/",
"sub_id" => "fb-ads-01",
]),
]);
$link = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $link["affiliate_link"] ?? "error";
// 2) Lấy danh sách link đã tạo
$q = http_build_query(["creator_username" => "__CREATOR__", "page" => 1, "page_size" => 50]);
$ch = curl_init("$base/partner/tiktok/affiliate/links?$q");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-Riohub-Api-Key: $key"],
]);
$links = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($links["links"] ?? []);
// 3) Lấy đơn hàng (tất cả filter đều tuỳ chọn)
$q = http_build_query([
"creator_username" => "__CREATOR__",
"order_id" => "584428814795835227,583754926547633737", // 1 hoặc list (verify postback)
"status" => "1,2", // 1=pending 2=settled 3=cancelled
"settlement_status" => "SETTLED",
"update_time_start" => 1778000000, // chỉ đơn cập nhật sau mốc này (sync tăng dần)
"sub1" => "u27765", // khớp vị trí 1 của tag
"page" => 1, "page_size" => 200,
]);
$ch = curl_init("$base/partner/tiktok/affiliate/orders?$q");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-Riohub-Api-Key: $key"],
]);
$orders = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($orders["orders"] ?? []);
// 4) Lấy thông tin sản phẩm affiliate (1 hoặc nhiều product_id)
$q = http_build_query(["creator_username" => "__CREATOR__", "product_id" => "1732152247872817576"]);
$ch = curl_init("$base/partner/tiktok/affiliate/products?$q");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-Riohub-Api-Key: $key"],
]);
$products = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($products["products"] ?? []);
const BASE = '__BASE__';
const KEY = 'YOUR_API_KEY';
// 1) Tạo link affiliate
const link = await fetch(`${BASE}/partner/tiktok/affiliate/links`, {
method: 'POST',
headers: { 'X-Riohub-Api-Key': KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
creator_username: '__CREATOR__',
product_url: 'https://vt.tiktok.com/XXXXXX/',
sub_id: 'fb-ads-01',
}),
}).then(r => r.json());
console.log(link.affiliate_link);
// 2) Lấy danh sách link đã tạo
const lq = new URLSearchParams({ creator_username: '__CREATOR__', page: '1', page_size: '50' });
const links = await fetch(`${BASE}/partner/tiktok/affiliate/links?${lq}`, {
headers: { 'X-Riohub-Api-Key': KEY },
}).then(r => r.json());
console.log(links.total, links.links);
// 3) Lấy đơn hàng (tất cả filter đều tuỳ chọn)
const q = new URLSearchParams({
creator_username: '__CREATOR__',
order_id: '584428814795835227,583754926547633737', // 1 hoặc list (verify postback)
status: '1,2', // 1=pending 2=settled 3=cancelled
settlement_status: 'SETTLED',
update_time_start: '1778000000', // chỉ đơn cập nhật sau mốc này (sync tăng dần)
sub1: 'u27765', // khớp vị trí 1 của tag
page: '1', page_size: '200',
});
const orders = await fetch(`${BASE}/partner/tiktok/affiliate/orders?${q}`, {
headers: { 'X-Riohub-Api-Key': KEY },
}).then(r => r.json());
console.log(orders.total, orders.orders);
// 4) Lấy thông tin sản phẩm affiliate (1 hoặc nhiều product_id)
const pq = new URLSearchParams({ creator_username: '__CREATOR__', product_id: '1732152247872817576' });
const products = await fetch(`${BASE}/partner/tiktok/affiliate/products?${pq}`, {
headers: { 'X-Riohub-Api-Key': KEY },
}).then(r => r.json());
console.log(products.found, products.products);
import requests
BASE = "__BASE__"
KEY = "YOUR_API_KEY"
H = {"X-Riohub-Api-Key": KEY}
# 1) Tạo link affiliate
link = requests.post(f"{BASE}/partner/tiktok/affiliate/links", headers=H, json={
"creator_username": "__CREATOR__",
"product_url": "https://vt.tiktok.com/XXXXXX/",
"sub_id": "fb-ads-01",
}).json()
print(link.get("affiliate_link"))
# 2) Lấy danh sách link đã tạo
links = requests.get(f"{BASE}/partner/tiktok/affiliate/links", headers=H, params={
"creator_username": "__CREATOR__", "page": 1, "page_size": 50,
}).json()
print(links.get("total"), links.get("links"))
# 3) Lấy đơn hàng (tất cả filter đều tuỳ chọn)
orders = requests.get(f"{BASE}/partner/tiktok/affiliate/orders", headers=H, params={
"creator_username": "__CREATOR__",
"order_id": "584428814795835227,583754926547633737", # 1 hoặc list (verify postback)
"status": "1,2", # 1=pending 2=settled 3=cancelled
"settlement_status": "SETTLED",
"update_time_start": 1778000000, # chỉ đơn cập nhật sau mốc này (sync tăng dần)
"sub1": "u27765", # khớp vị trí 1 của tag
"page": 1, "page_size": 200,
}).json()
print(orders.get("total"), orders.get("orders"))
# 4) Lấy thông tin sản phẩm affiliate (1 hoặc nhiều product_id)
products = requests.get(f"{BASE}/partner/tiktok/affiliate/products", headers=H, params={
"creator_username": "__CREATOR__", "product_id": "1732152247872817576",
}).json()
print(products.get("found"), products.get("products"))
Tích hợp bằng AI
Sao chép cả khối Markdown dưới đây, dán cho AI (ChatGPT/Claude/Copilot…) kèm yêu cầu của bạn — AI sẽ tự viết code tích hợp. Không chứa key thật: giữ YOUR_API_KEY và thay bằng key của bạn lúc chạy.
# RioHub × TikTok Shop Affiliate API — Spec tích hợp
> Tài liệu cập nhật: 11/06/2026
Bạn là kỹ sư tích hợp. Hãy viết code gọi các API dưới đây theo ngôn ngữ tôi chỉ định.
Đọc API key từ biến môi trường (KHÔNG hardcode, KHÔNG để lộ key); thay `YOUR_API_KEY` bằng key thật khi chạy.
## Base URL
`__BASE__`
## Xác thực
Mọi request kèm header: `X-Riohub-Api-Key: YOUR_API_KEY`
- `401` key sai/thiếu · `403` creator không thuộc tài khoản của key · `404` creator chưa kết nối
- `429` vượt giới hạn (300 req/phút, 100.000 req/ngày) — đọc header `Retry-After` rồi thử lại.
## 1) POST `/partner/tiktok/affiliate/links` — Tạo link affiliate
Body JSON:
- `creator_username` (bắt buộc): username creator đã kết nối, vd `__CREATOR__`
- `product_url` (bắt buộc*): URL sản phẩm (link rút gọn vt.tiktok.com / link trực tiếp) hoặc `product_id`. (*hoặc gửi `product_id`)
- `sub_id` (bắt buộc): nhãn theo dõi, 1–128 ký tự `[A-Za-z0-9_-]`. Có thể gói tối đa 4 sub theo vị trí, phân tách bằng `-` (vd `abc-def--` → sub1=abc, sub2=def, sub3/4=rỗng); RioHub tự tách thành `sub1..sub4` để lọc đơn theo từng vị trí. Lưu ý: giá trị mỗi sub KHÔNG được chứa `-` (đó là dấu phân tách).
- `type` (tuỳ chọn): mặc định `PRODUCT`
- `channel` (tuỳ chọn): nhãn nguồn traffic, mặc định `riokupon`. 1–64 ký tự `[A-Za-z0-9_-]`
Request:
{ "creator_username": "__CREATOR__", "product_url": "https://vt.tiktok.com/XXXXXX/", "sub_id": "fb-ads-01" }
Response 200:
{ "affiliate_link": "https://vt.tiktok.com/XXXXXX/", "sub_id": "fb-ads-01", "product_id": "1729...", "creator_username": "__CREATOR__" }
Lỗi 422 `product_not_promotable`: sản phẩm không có hoa hồng hoặc chưa được shop duyệt.
## 2) GET `/partner/tiktok/affiliate/links` — Lấy danh sách link đã tạo
Liệt kê link đã tạo qua API (source=`api`) cho creator, kèm số đơn & hoa hồng theo `sub_id`.
Query params:
- `creator_username` (bắt buộc)
- `sub_id` (tuỳ chọn): khớp **chuỗi con** trên tag; `channel` (tuỳ chọn): lọc nguồn traffic
- `sub1`, `sub2`, `sub3`, `sub4` (tuỳ chọn): lọc khớp chính xác theo từng vị trí của tag
- `time_start`, `time_end` (tuỳ chọn): unix giây hoặc `Y-m-d H:i:s` (lọc theo ngày tạo, end không bao gồm)
- `page` (mặc định 1), `page_size` (mặc định 50, tối đa 200)
Response 200:
{ "creator_username": "__CREATOR__", "page": 1, "page_size": 50, "total": 8,
"links": [ { "id": 42, "material_id": "1729...", "affiliate_link": "https://vt.tiktok.com/XXXXXX/",
"channel": "riokupon", "sub_id": "fb-ads-01", "order_count": 3, "est_commission": "37.50",
"settled_commission": "12.50", "currency": "VND", "created_at": "..." } ] }
## 3) GET `/partner/tiktok/affiliate/orders` — Lấy đơn hàng
Query params:
- `creator_username` (bắt buộc)
- `time_start`, `time_end` (tuỳ chọn): unix giây hoặc `Y-m-d H:i:s` (lọc từ / đến, end không bao gồm)
- `sub_id` (tuỳ chọn): khớp **chuỗi con** trên tag đầy đủ (vd `abc` khớp `abc-def---`)
- `sub1`, `sub2`, `sub3`, `sub4` (tuỳ chọn): lọc **khớp chính xác** theo từng vị trí của tag (tag tách bằng `-`); kết hợp nhiều sub = AND
- `order_id` (tuỳ chọn): 1 mã đơn hoặc danh sách phân tách bằng dấu phẩy (tối đa 200) — dùng để verify postback hoặc gom 1 đợt (vd hold postback ~5p rồi lấy 1 loạt). Nên đặt `page_size` đủ lớn.
- `settlement_status` (tuỳ chọn): 1 giá trị hoặc danh sách phân tách bằng dấu phẩy (vd `SETTLED,AWAITING PAYMENT`)
- `status` (tuỳ chọn): trạng thái chuẩn hoá, 1 giá trị hoặc list (`1`=pending · `2`=settled · `3`=cancelled/refunded)
- `update_time_start`, `update_time_end` (tuỳ chọn): unix giây, lọc theo thời điểm đơn **được cập nhật** (end không bao gồm) — dùng để kéo đơn vừa đổi settlement/refund (sync tăng dần)
- `product_id` (tuỳ chọn): 1 hoặc list (tối đa 100) — lọc đơn theo sản phẩm
- `content_type` (tuỳ chọn): 1 hoặc list, theo nguồn nội dung (VIDEO/LIVE/SHOWCASE/LINKSHARE — passthrough)
- `fully_refunded` (tuỳ chọn): `0` | `1`
- `page` (mặc định 1), `page_size` (mặc định 50, tối đa 200)
Response 200:
{ "creator_username": "__CREATOR__", "page": 1, "page_size": 50, "total": 12,
"orders": [ { "order_id": "...", "sku_id": "...", "product_id": "...", "product_name": "...",
"sub_id": "abc-def--", "sub1": "abc", "sub2": "def", "sub3": "", "sub4": "",
"quantity": 1, "refunded_quantity": 0, "fully_refunded": 0, "est_commission": "12.50",
"actual_commission": null, "currency": "VND", "settlement_status": "AWAITING PAYMENT",
"status": 1, "tt_order_status": 100, "content_type": "VIDEO", "create_time": 1749513600 } ] }
Kiểu JSON: cột số nguyên = number, cột tiền/decimal & ID lớn = string.
Enum các field trạng thái trong orders[]:
- `status` (number): 1=pending · 2=settled · 3=cancelled/refunded
- `tt_order_status` (number): 100=pending · 103=settled · 104=cancelled/refunded
- `settlement_status` / `payment_status` (string, passthrough TikTok): AWAITING PAYMENT · To-SETTLE · SETTLED · REFUNDED
- `fully_refunded` (number): 0 | 1
- `content_type` (string, passthrough): VIDEO · LIVE · SHOWCASE · LINKSHARE · …
- `actual_commission` (string|null): null khi chưa đối soát
- `sub1`..`sub4` (string): tag tách theo `-` (vị trí trống = `""`)
## 4) GET `/partner/tiktok/affiliate/products` — Lấy thông tin sản phẩm affiliate
API tạo link không kèm thông tin sản phẩm — dùng endpoint này lấy tên/ảnh/giá/hoa hồng theo `product_id` (trong phạm vi quyền của creator). RioHub cache thông tin sản phẩm 24h: id đã có trong cache trả về ngay, id mới/quá 24h mới gọi TikTok → giảm tải, nhanh hơn.
Query params:
- `creator_username` (bắt buộc)
- `product_id` (bắt buộc): 1 id hoặc danh sách phân tách bằng dấu phẩy (tối đa 100)
Response 200 (`products[]` = object passthrough TikTok V202509, snake_case):
{ "creator_username": "__CREATOR__", "requested": 1, "found": 1,
"products": [ { "id": "1732...", "title": "...", "main_image_url": "https://...",
"detail_link": "https://shop.tiktok.com/view/product/1732...",
"sale_region": "VN", "has_inventory": true, "units_sold": 62030,
"commission": { "rate": 600, "amount": "3299.94 - 5099.94", "currency": "VND" },
"shop_ads_commission": { "rate": 200 },
"sales_price": { "minimum_amount": "", "maximum_amount": "", "currency": "" },
"original_price": { "minimum_amount": "89000", "maximum_amount": "139000", "currency": "VND" },
"shop": { "name": "..." },
"category_chains": [ { "id": "700791", "is_leaf": true, "local_name": "Dao cạo", "parent_id": "849288" } ] } ],
"not_found": [] }
Ghi chú field: `commission.rate` raw ÷100 = % (600 = 6%); `commission.amount` có thể là khoảng "min - max";
`sales_price` có thể rỗng → dùng `original_price`; `units_sold` lũy kế; `has_inventory` còn hàng; ngành lá = phần tử `is_leaf:true`.
Id không lấy được (không đủ điều kiện / không tồn tại) nằm trong `not_found`. Dữ liệu cache 24h.
## 5) Postback (webhook) — RioHub POST về URL của bạn
Event JSON: `event` ∈ { order.created, order.updated, order.refunded }; `event_id` (UUID) idempotency; `occurred_at` ISO-8601.
`data` chứa các field như orders[] (status 1/2/3, order_status_raw = settlement_status gốc). Xác minh chữ ký header `X-Riohub-Signature: t=,v1=`.
## Yêu cầu code
- Đọc key từ env; có cơ chế retry khi gặp 429 (tôn trọng `Retry-After`).
- Bắt và log rõ các lỗi 401/403/404/422.
- Hàm tạo link nhận (product_url, sub_id) và trả về `affiliate_link`.
Thử nghiệm trực tiếp
Nhập dữ liệu và gọi API thật bằng key của bạn — phản hồi hiển thị bên dưới.
Tự dùng key của tài khoản này (tạo sẵn 1 key "Playground" khi bạn bấm Gửi). Hoặc dán key khác để thử.
Phản hồi
Postback qua Callback URL
RioHub POST JSON có chữ ký HMAC về URL của bạn mỗi khi đơn affiliate phát sinh / cập nhật / hoàn. Theo tài khoản (1 endpoint), áp dụng mọi creator đã kết nối. Bỏ trống URL nếu chỉ dùng Telegram bên dưới.
Nếu dùng: phải HTTPS, trả về HTTP 2xx trong vòng 5s để xác nhận đã nhận. Để trống nếu chỉ dùng Telegram.
Giữ bí mật. Mỗi request kèm header X-Riohub-Signature: t=<ts>,v1=<hmac>.
Retry: nếu không nhận 2xx, RioHub thử lại theo backoff 1m → 5m → 30m → 2h → 6h (tối đa 6 lần) rồi đánh dấu dead.
Lịch sử gửi gần đây
Thời điểm
Sự kiện
Order
Postback (HTTP)
Telegram
Lần thử
Lỗi
—
Thông báo qua Telegram
Gửi 1 tin nhắn tóm tắt mỗi đơn về Telegram của bạn — kênh độc lập, dùng bot riêng. Lưu riêng, không ảnh hưởng cấu hình URL ở trên. Cách lấy token & chat ID ▾
Chưa bật
Mở @BotFather trên Telegram → gửi /newbot → nhận bot token dạng 123456789:ABC-def....
Nhắn cho bot (chat riêng), hoặc thêm bot vào group/channel.
Lấy chat ID: mở https://api.telegram.org/bot<token>/getUpdates sau khi nhắn bot → copy chat.id. Channel công khai dùng @tenkenh.
Token được lưu phía máy chủ, không hiển thị lại.
Để trống & lưu = tắt Telegram.
Nút Gửi test bắn 1 tin ping tới mọi kênh đang bật (URL & Telegram).