Posts
18/10/25Khoảng 6 phútapiapifacebookposts
Endpoints
1. Lấy danh sách posts
GET /api/v2/fb-posts
Tham số
| Tên | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| page | Integer | Không | Số trang (mặc định: 1) |
| limit | Integer | Không | Số lượng items per page (mặc định: 10) |
| status | Integer | Không | Lọc theo status (0 hoặc 1) |
| post_type | String | Không | Lọc theo loại post (product, interaction) |
Response
{
"status": "success",
"data": [
{
"id": 1,
"title": "Tiêu đề bài viết",
"content": "Nội dung bài viết",
"post_type": "product",
"media_type": "image",
"status": 1,
"created_at": "2024-01-01 10:00:00",
"media_url": "/uploads/posts/20240101/image.jpg"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 100,
"total_pages": 10
}
}CURL Example
curl -X GET "https://kkdemo.kkwebsite.com/api/v2/fb-posts?page=1&limit=20&status=1" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"N8N Example
Cấu hình HTTP Request Node:
- URL:
https://kkdemo.kkwebsite.com/api/v2/fb-posts - Method:
GET - Query Parameters:
page: 1 limit: 20 status: 1 - Headers:
Authorization: Bearer YOUR_TOKEN_HERE
PHP Example
function getFbPosts($token, $page = 1, $limit = 10, $status = null) {
$url = 'https://kkdemo.kkwebsite.com/api/v2/fb-posts';
$params = [
'page' => $page,
'limit' => $limit
];
if ($status !== null) {
$params['status'] = $status;
}
$url .= '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = getFbPosts('YOUR_TOKEN_HERE', 1, 20, 1);Python Example
import requests
def get_fb_posts(token, page=1, limit=10, status=None):
url = 'https://kkdemo.kkwebsite.com/api/v2/fb-posts'
params = {
'page': page,
'limit': limit
}
if status is not None:
params['status'] = status
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, params=params, headers=headers)
return response.json()
# Sử dụng
result = get_fb_posts('YOUR_TOKEN_HERE', page=1, limit=20, status=1)2. Lấy chi tiết một post
GET /api/v2/fb-posts/{id}
Response
{
"status": "success",
"data": {
"id": 1,
"title": "Tiêu đề bài viết",
"content": "Nội dung bài viết",
"post_type": "product",
"media_type": "image",
"assistant_id": 1,
"status": 1,
"post_to": "group",
"comments_payload": [
{
"comment": "Bình luận mẫu",
"delay": 30
}
],
"seeding_payload": [
{
"comment": "Seeding comment",
"delay": 60
}
],
"file_download": 1,
"seeding_check": 1,
"comments_check": 1,
"created_at": "2024-01-01 10:00:00",
"updated_at": "2024-01-01 10:00:00",
"media": [
{
"id": 1,
"fb_post_id": 1,
"media_url": "/uploads/posts/20240101/image.jpg",
"media_type": "image"
}
]
}
}CURL Example
curl -X GET "https://kkdemo.kkwebsite.com/api/v2/fb-posts/1" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"N8N Example
Cấu hình HTTP Request Node:
- URL:
https://kkdemo.kkwebsite.com/api/v2/fb-posts/1 - Method:
GET - Headers:
Authorization: Bearer YOUR_TOKEN_HERE
PHP Example
function getFbPost($id, $token) {
$url = "https://kkdemo.kkwebsite.com/api/v2/fb-posts/{$id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = getFbPost(1, 'YOUR_TOKEN_HERE');Python Example
import requests
def get_fb_post(post_id, token):
url = f'https://kkdemo.kkwebsite.com/api/v2/fb-posts/{post_id}'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, headers=headers)
return response.json()
# Sử dụng
result = get_fb_post(1, 'YOUR_TOKEN_HERE')3. Tạo bài viết mới
POST /api/v2/fb-posts
Tham số
| Tên | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| title | String | Có | Tiêu đề bài viết (tối đa 255 ký tự) |
| content | String | Không | Nội dung bài viết |
| post_type | String | Có | Loại post (product, interaction) |
| media_type | String | Có | Loại media (video, image) |
| assistant_id | Integer | Không | ID của assistant |
| status | Integer | Không | Trạng thái (0 hoặc 1) |
| post_to | String | Không | Đăng lên (group, fanpage, profile, all) |
| file_download | Integer | Không | Tải file (0 hoặc 1) |
| media | Array | Không | Danh sách URL media hoặc file upload |
| comments | Array | Không | Danh sách bình luận |
| seeding | Array | Không | Danh sách seeding |
Request Body
{
"title": "Tiêu đề bài viết",
"content": "Nội dung bài viết",
"post_type": "product",
"media_type": "image",
"assistant_id": 1,
"status": 1,
"post_to": "group",
"file_download": 1,
"media": [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg"
],
"comments": [
{
"comment": "Bình luận mẫu",
"delay": 30
}
],
"seeding": [
{
"comment": "Seeding comment",
"delay": 60
}
]
}Response
{
"status": "success",
"message": "Tạo bài viết thành công",
"data": {
"id": 1,
"title": "Tiêu đề bài viết",
"content": "Nội dung bài viết",
"media": [
"/uploads/posts/20240101/image1.jpg",
"/uploads/posts/20240101/image2.jpg"
]
}
}CURL Example (JSON)
curl -X POST https://kkdemo.kkwebsite.com/api/v2/fb-posts \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"title": "Test Post",
"content": "Test Content",
"post_type": "product",
"media_type": "image",
"media": ["https://example.com/image1.jpg"],
"file_download": 1
}'CURL Example (File Upload)
curl -X POST https://kkdemo.kkwebsite.com/api/v2/fb-posts \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-F "data={\"title\":\"Test Post\",\"content\":\"Test Content\",\"post_type\":\"product\"}" \
-F "media[]=@image1.jpg" \
-F "media[]=@image2.jpg"N8N Example
Cấu hình HTTP Request Node:
- URL:
https://kkdemo.kkwebsite.com/api/v2/fb-posts - Method:
POST - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_TOKEN_HERE Content-Type: application/json - Body (JSON):
{ "title": "Test Post", "content": "Test Content", "post_type": "product", "media_type": "image", "media": ["https://example.com/image1.jpg"], "file_download": 1 }
PHP Example
function createFbPost($data, $token) {
$url = 'https://kkdemo.kkwebsite.com/api/v2/fb-posts';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$data = [
'title' => 'Test Post',
'content' => 'Test Content',
'post_type' => 'product',
'media_type' => 'image',
'media' => ['https://example.com/image1.jpg'],
'file_download' => 1
];
$result = createFbPost($data, 'YOUR_TOKEN_HERE');Python Example
import requests
import json
def create_fb_post(data, token):
url = 'https://kkdemo.kkwebsite.com/api/v2/fb-posts'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
data = {
'title': 'Test Post',
'content': 'Test Content',
'post_type': 'product',
'media_type': 'image',
'media': ['https://example.com/image1.jpg'],
'file_download': 1
}
result = create_fb_post(data, 'YOUR_TOKEN_HERE')4. Cập nhật bài viết
PUT /api/v2/fb-posts/{id}
Tham số
| Tên | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| title | String | Không | Tiêu đề mới |
| content | String | Không | Nội dung mới |
| status | Integer | Không | Trạng thái mới (0 hoặc 1) |
| post_type | String | Không | Loại post mới |
| media_type | String | Không | Loại media mới |
Request Body
{
"title": "Tiêu đề mới",
"content": "Nội dung mới",
"status": 0
}Response
{
"status": "success",
"message": "Cập nhật bài viết thành công",
"data": {
"id": 1,
"updated_fields": ["title", "content", "status"]
}
}CURL Example
curl -X PUT https://kkdemo.kkwebsite.com/api/v2/fb-posts/1 \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"title": "Tiêu đề mới",
"content": "Nội dung mới",
"status": 0
}'N8N Example
Cấu hình HTTP Request Node:
- URL:
https://kkdemo.kkwebsite.com/api/v2/fb-posts/1 - Method:
PUT - Send Body:
true - Body Type:
JSON - Headers:
Authorization: Bearer YOUR_TOKEN_HERE Content-Type: application/json - Body (JSON):
{ "title": "Tiêu đề mới", "content": "Nội dung mới", "status": 0 }
PHP Example
function updateFbPost($id, $data, $token) {
$url = "https://kkdemo.kkwebsite.com/api/v2/fb-posts/{$id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$data = [
'title' => 'Tiêu đề mới',
'content' => 'Nội dung mới',
'status' => 0
];
$result = updateFbPost(1, $data, 'YOUR_TOKEN_HERE');Python Example
import requests
import json
def update_fb_post(post_id, data, token):
url = f'https://kkdemo.kkwebsite.com/api/v2/fb-posts/{post_id}'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
response = requests.put(url, headers=headers, data=json.dumps(data))
return response.json()
# Sử dụng
data = {
'title': 'Tiêu đề mới',
'content': 'Nội dung mới',
'status': 0
}
result = update_fb_post(1, data, 'YOUR_TOKEN_HERE')5. Xóa bài viết
DELETE /api/v2/fb-posts/{id}
Response
{
"status": "success",
"message": "Xóa bài viết thành công",
"data": {
"id": 1
}
}CURL Example
curl -X DELETE https://kkdemo.kkwebsite.com/api/v2/fb-posts/1 \
-H "Authorization: Bearer YOUR_TOKEN_HERE"N8N Example
Cấu hình HTTP Request Node:
- URL:
https://kkdemo.kkwebsite.com/api/v2/fb-posts/1 - Method:
DELETE - Headers:
Authorization: Bearer YOUR_TOKEN_HERE
PHP Example
function deleteFbPost($id, $token) {
$url = "https://kkdemo.kkwebsite.com/api/v2/fb-posts/{$id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = deleteFbPost(1, 'YOUR_TOKEN_HERE');Python Example
import requests
def delete_fb_post(post_id, token):
url = f'https://kkdemo.kkwebsite.com/api/v2/fb-posts/{post_id}'
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.delete(url, headers=headers)
return response.json()
# Sử dụng
result = delete_fb_post(1, 'YOUR_TOKEN_HERE')6. Lấy random bài viết
GET /api/v2/fb-posts/random
Tham số
| Tên | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| update | String | Không | Nếu = "posted", sẽ cập nhật status của post thành 2 |
Response
{
"status": "success",
"data": {
"post": {
"id": 1,
"title": "Tiêu đề bài viết",
"content": "Nội dung bài viết",
"post_type": "product",
"media_type": "image",
"status": 1,
"created_at": "2024-01-01 10:00:00"
}
}
}CURL Example
curl -X GET "https://kkdemo.kkwebsite.com/api/v2/fb-posts/random" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"N8N Example
Cấu hình HTTP Request Node:
- URL:
https://kkdemo.kkwebsite.com/api/v2/fb-posts/random - Method:
GET - Headers:
Authorization: Bearer YOUR_TOKEN_HERE
PHP Example
function getRandomFbPost($token, $update = null) {
$url = 'https://kkdemo.kkwebsite.com/api/v2/fb-posts/random';
if ($update) {
$url .= '?update=' . urlencode($update);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token
]);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Sử dụng
$result = getRandomFbPost('YOUR_TOKEN_HERE', 'posted');Python Example
import requests
def get_random_fb_post(token, update=None):
url = 'https://kkdemo.kkwebsite.com/api/v2/fb-posts/random'
params = {}
if update:
params['update'] = update
headers = {
'Authorization': f'Bearer {token}'
}
response = requests.get(url, params=params, headers=headers)
return response.json()
# Sử dụng
result = get_random_fb_post('YOUR_TOKEN_HERE', 'posted')Error Responses
Validation Error
{
"code": "VALIDATION_ERROR",
"message": {
"title": "Tiêu đề không được để trống",
"content": "Nội dung không được để trống"
}
}Not Found
{
"code": "NOT_FOUND",
"message": "Không tìm thấy bài viết"
}System Error
{
"code": "SYSTEM_ERROR",
"message": "Có lỗi xảy ra: Chi tiết lỗi"
}Validation Rules
Post Data
title: Tối đa 255 ký tựcontent: Không bắt buộcpost_type: Chỉ chấp nhận "product" hoặc "interaction"media_type: Chỉ chấp nhận "video" hoặc "image"assistant_id: Phải là sốstatus: Chỉ chấp nhận 0 hoặc 1post_to: Chỉ chấp nhận "group", "fanpage", "profile", "all"file_download: Chỉ chấp nhận 0 hoặc 1
Media
- Hỗ trợ upload file hoặc URL
- File upload: Tối đa 10MB, định dạng JPG, PNG, GIF
- URL: Phải là URL hợp lệ, tối đa 15 hình ảnh
Comments/Seeding
- Mỗi item phải có
commentvàdelay delayphải là số (giây)
Status Codes
- 200: Success
- 201: Created
- 204: No Content
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 500: Internal Server Error
Rate Limit
- 1000 requests per hour
