เอกสาร API
REST API สำหรับสร้าง จัดการ และดึงสถิติของลิงก์สั้น ทุก endpoint ตอบกลับเป็น JSON และต้องแนบ API key เสมอ
Base URL
https://link.zerofriction.devการยืนยันตัวตน
Authorization: Bearer zero_xxxxxใช้ header X-API-Key แทนก็ได้
Endpoints
POST
/api/v1/linksสร้างลิงก์สั้นพารามิเตอร์
url— จำเป็น · ลิงก์ปลายทาง (ไม่ใส่ http/https จะเติม https:// ให้)code— ไม่บังคับ · โค้ดที่ต้องการ a-z A-Z 0-9 _ - ยาว 3–64 ตัวtitle— ไม่บังคับ · ชื่อเรียกไว้ดูในหน้าจัดการexpires_at— ไม่บังคับ · วันหมดอายุแบบ ISO 8601 เช่น 2026-12-31T23:59:59Zdomain— ไม่บังคับ · โดเมนของคุณที่ยืนยันแล้ว (ไม่ใส่ = โดเมนหลักของระบบ)
request body
{
"url": "https://example.com/campaign",
"code": "promo-2026",
"title": "แคมเปญปีใหม่",
"expires_at": "2026-12-31T23:59:59Z"
}response
{
"id": 42,
"code": "promo-2026",
"short_url": "https://link.zerofriction.dev/promo-2026",
"url": "https://example.com/campaign",
"title": "แคมเปญปีใหม่",
"status": "active",
"is_active": true,
"clicks": 0,
"expires_at": "2026-12-31T23:59:59.000Z",
"last_clicked_at": null,
"created_at": "2026-08-05T04:21:00.000Z"
}GET
/api/v1/linksดูลิงก์ทั้งหมดพารามิเตอร์
limit— จำนวนต่อหน้า 1–200 (ค่าเริ่มต้น 50)offset— ข้ามกี่รายการ (ค่าเริ่มต้น 0)search— ค้นหาจากโค้ดหรือชื่อเรียก
response
{
"data": [ { "code": "promo-2026", "clicks": 128, ... } ],
"pagination": { "total": 12, "limit": 50, "offset": 0 }
}GET
/api/v1/links/{code}ดูลิงก์รายตัวPATCH
/api/v1/links/{code}แก้ไขลิงก์พารามิเตอร์
url— เปลี่ยนปลายทางtitle— เปลี่ยนชื่อเรียกexpires_at— ตั้ง/ยกเลิกวันหมดอายุ (ส่ง null เพื่อยกเลิก)is_active— true/false เปิด-ปิดการใช้งาน
request body
{ "expires_at": null, "is_active": false }DELETE
/api/v1/links/{code}ลบลิงก์ (สถิติจะถูกลบด้วย)response
{ "deleted": true, "code": "promo-2026" }GET
/api/v1/links/{code}/statsดึงสถิติของลิงก์พารามิเตอร์
days— ช่วงย้อนหลังของกราฟ 1–365 วัน (ค่าเริ่มต้น 30)
response
{
"code": "promo-2026",
"total_clicks": 128,
"unique_visitors": 96,
"clicks_today": 7,
"clicks_7d": 41,
"timeline": [ { "date": "2026-08-05", "clicks": 7 } ],
"breakdown": {
"referrers": [ { "label": "facebook.com", "value": 40 } ],
"devices": [ { "label": "mobile", "value": 88 } ],
"browsers": [ { "label": "Chrome", "value": 61 } ],
"operating_systems": [ { "label": "Android", "value": 52 } ],
"countries": []
}
}GET
/api/v1/domainsดูโดเมนที่ใช้สร้างลิงก์ได้response
{
"data": [
{ "domain": "link.zerofriction.dev", "status": "active", "is_system": true, "links": 12, "dns": null },
{
"domain": "go.example.com",
"status": "pending",
"is_system": false,
"links": 0,
"dns": { "type": "CNAME", "name": "go", "value": "xxxx.up.railway.app", "current": null }
}
]
}GET
/api/v1/meตรวจสอบคีย์และดูข้อมูลบัญชีresponse
{ "id": 1, "email": "[email protected]", "total_links": 12, "total_clicks": 480 }ตัวอย่างโค้ด
JavaScript / Node.js
const res = await fetch("https://link.zerofriction.dev/api/v1/links", {
method: "POST",
headers: {
"Authorization": "Bearer " + process.env.ZERO_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com/campaign",
expires_at: "2026-12-31T23:59:59Z",
}),
});
const link = await res.json();
console.log(link.short_url); // https://link.zerofriction.dev/aB3xY9zPython
import os, requests
res = requests.post(
"https://link.zerofriction.dev/api/v1/links",
headers={"Authorization": f"Bearer {os.environ['ZERO_API_KEY']}"},
json={"url": "https://example.com/campaign", "code": "promo-2026"},
)
print(res.json()["short_url"])รหัสข้อผิดพลาด
| HTTP | code | ความหมาย |
|---|---|---|
| 400 | validation_error | ข้อมูลที่ส่งมาไม่ถูกต้อง เช่น URL ผิดรูปแบบ |
| 401 | unauthorized | ไม่ได้แนบ API key หรือคีย์ถูกเพิกถอนแล้ว |
| 404 | not_found | ไม่พบลิงก์ตามโค้ดที่ระบุ |
| 409 | conflict | โค้ดนี้มีคนใช้ไปแล้ว |
| 429 | rate_limited | เรียกเกิน 120 ครั้ง/นาที |
error response
{
"error": {
"message": "โค้ด \"promo-2026\" ถูกใช้ไปแล้ว กรุณาเลือกใหม่",
"code": "conflict",
"status": 409
}
}