API Reference

Overview

LinkPilot API cho phép bạn quản lý short links, domains và analytics thông qua các endpoint RESTful.

Base URL

https://linkpilot.theyourlist.com/api/v1

Authentication

Mọi request đều yêu cầu API Key. Có 2 cách truyền key:

Header (Khuyến nghị)

Authorization: Bearer lp_your_api_key_here

Query Parameter

GET /api/v1/links?api_key=lp_your_api_key_here

Response khi không xác thực

{
  "success": false,
  "error": "Unauthorized"
}

HTTP Status: 401 Unauthorized

Response Format

Thành công

{
  "success": true,
  "data": { ... }
}

Lỗi

{
  "success": false,
  "error": "Error message here"
}

Endpoints

GET/api/v1/links

Lấy danh sách links

Query Parameters

ParameterTypeDescription
pagenumberTrang hiện tại (default: 1)
limitnumberSố item mỗi trang (default: 20, max: 100)
domain_idstringLọc theo domain
searchstringTìm theo tên hoặc slug

POST/api/v1/links

Tạo link mới

Request Body

{
  "name": "Shopee Christmas Sale",
  "slug": "xmas-sale",
  "default_url": "https://shopee.vn/sale/christmas",
  "domain_id": "clxxx...",
  "is_enabled": true,
  "expires_at": "2025-12-31T23:59:59Z",
  "geo_targets": [
    {
      "country_code": "VN",
      "target_url": "https://shopee.vn/sale"
    }
  ]
}

GET/api/v1/links/{id}

Lấy chi tiết link

PUT/api/v1/links/{id}

Cập nhật link

DELETE/api/v1/links/{id}

Xóa link

GET/api/v1/domains

Lấy danh sách domains

POST/api/v1/domains

Thêm domain mới

GET/api/v1/links/{id}/analytics

Lấy analytics của link

Query Parameters

ParameterTypeDescription
start_datestringNgày bắt đầu (YYYY-MM-DD)
end_datestringNgày kết thúc (YYYY-MM-DD)
group_bystringNhóm theo: day, country, referer

GET/api/v1/stats

Lấy thống kê tổng quan

Error Codes

HTTP StatusErrorDescription
400Bad RequestRequest không hợp lệ
401UnauthorizedThiếu hoặc sai API Key
403ForbiddenKhông có quyền truy cập
404Not FoundResource không tồn tại
409ConflictDuplicate (VD: slug đã tồn tại)
429Too Many RequestsRate limit exceeded
500Internal Server ErrorLỗi server

Code Examples

cURL

curl -X POST "https://linkpilot.theyourlist.com/api/v1/links" \
  -H "Authorization: Bearer lp_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"name":"Test Link","slug":"test","default_url":"https://google.com","domain_id":"clxxx"}'

JavaScript

const response = await fetch('https://linkpilot.theyourlist.com/api/v1/links', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer lp_your_api_key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Test Link',
    slug: 'test',
    default_url: 'https://google.com',
    domain_id: 'clxxx'
  })
});

const data = await response.json();
console.log(data);

Python

import requests

response = requests.post(
    'https://linkpilot.theyourlist.com/api/v1/links',
    headers={
        'Authorization': 'Bearer lp_your_api_key',
        'Content-Type': 'application/json'
    },
    json={
        'name': 'Test Link',
        'slug': 'test',
        'default_url': 'https://google.com',
        'domain_id': 'clxxx'
    }
)

print(response.json())

PHP

<?php
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://linkpilot.theyourlist.com/api/v1/links',
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer lp_your_api_key',
        'Content-Type: application/json'
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'name' => 'Test Link',
        'slug' => 'test',
        'default_url' => 'https://google.com',
        'domain_id' => 'clxxx'
    ]),
    CURLOPT_RETURNTRANSFER => true
]);

$response = curl_exec($ch);
curl_close($ch);

print_r(json_decode($response, true));

Rate Limiting

  • Limit: 1000 requests / phút / API Key
  • Headers:
    • X-RateLimit-Limit: Giới hạn
    • X-RateLimit-Remaining: Số request còn lại
    • X-RateLimit-Reset: Thời điểm reset (Unix timestamp)