{"openapi": "3.0.3", "info": {"title": "DoLink API", "version": "43.2", "description": "API quan tri he thong link cau DoLink. Moi route /api/* yeu cau header X-Admin-Token hoac X-API-Key (1 trong 2). Duong dan trong spec la duong dan sau diem mount (servers.url)."}, "servers": [{"url": "/go", "description": "Diem mount cua DoLink (vd /go tren VPS, / khi chay local)"}], "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "paths": {"/health": {"get": {"summary": "Health check", "description": "Khong can auth. Tra ok/time.", "security": [], "responses": {"200": {"description": "Server dang chay"}}}}, "/openapi.json": {"get": {"summary": "OpenAPI spec", "description": "Tai lieu API dang doc (khong chua secret).", "security": [], "responses": {"200": {"description": "OpenAPI 3.0 JSON"}}}}, "/api/links": {"get": {"summary": "Danh sach link", "description": "Tra links (kem share_url, so lieu tong hop).", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}, "post": {"summary": "Tao link", "description": "Truong bat buoc: title, destination. Xem LinkInput.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"201": {"description": "Link", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Link"}}}}, "400": {"description": "Loi", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkInput"}}}}}}, "/api/links/{id}": {"put": {"summary": "Sua link", "description": "Chi gui cac truong muon doi.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "Link", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Link"}}}}, "400": {"description": "Loi", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "404": {"description": "Loi", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}, "requestBody": {"required": false, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LinkInput"}}}}, "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "integer"}}]}, "delete": {"summary": "Xoa link", "description": "Xoa ca link va toan bo events cua no.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "Da xoa"}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "404": {"description": "Loi", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}, "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "integer"}}]}}, "/api/links/{id}/stats": {"get": {"summary": "So lieu 1 link", "description": "Click/view/CTR, thiet bi, trinh duyet, he dieu hanh, nguon, quoc gia, dich, A/B, heatmap gio, fraud, canh bao, moc click da bao (milestone_hit), moc view da bao (view_milestone_hit), breakdown view+click theo quoc gia va host nguon (traffic_by_country, traffic_by_referrer_host).", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/links/{id}/events.csv": {"get": {"summary": "Xuat CSV events", "description": "CSV: thoi gian, loai view/click, nguon, thiet bi, quoc gia, dich, trinh duyet, he dieu hanh.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "File CSV", "content": {"text/csv": {"schema": {"type": "string"}}}}}}}, "/api/links/{id}/duplicate": {"post": {"summary": "Nhan ban link", "description": "Tao ban sao voi slug moi.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"201": {"description": "Link", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Link"}}}}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "404": {"description": "Loi", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}}}, "/api/links/{id}/health": {"post": {"summary": "Kiem tra dich", "description": "Server tu mo link dich (timeout 5s, toi da 3 redirect), luu trang thai gan nhat.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/links/check-all-destinations": {"post": {"summary": "Kiem tra tat ca dich", "description": "Kiem tra suc khoe dich cua moi link, cap nhat last_status, tra ve danh sach dich chet (de bat auto_fallback cuu traffic) + danh sach slug da gui canh bao link.destination_dead qua webhook (chi khi link moi chuyen sang chet) + danh sach slug da gui canh bao link.expiring_soon qua webhook (chi khi link sap het han trong hom nay/ngay mai va chua bao cho ngay het han do). v24: luong nen tu dong chay cung luot quet nay theo nhip DOLINK_AUTO_CHECK_MINUTES nhung chi cho link bat auto_monitor.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/links/{id}/webhook-test": {"post": {"summary": "Test webhook", "description": "Gui dong bo 1 su kien link.click.test toi webhook_url cua link.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/links/{id}/auto-optimize": {"post": {"summary": "Chot A/B ngay", "description": "Danh gia va chot ban thang ngay ca khi link khong bat tu toi uu.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/stats/overview": {"get": {"summary": "Tong quan he thong", "description": "Tong click/view, bieu do 14 ngay, heatmap gio, quoc gia, trinh duyet, he dieu hanh, fraud, canh bao tut click, thong ke theo thu muc, nguon theo domain, quoc gia toan he thong, thiet bi toan he thong, thong ke theo tag, bien the A/B toan he thong, thong ke theo chien dich UTM, link hieu qua nhat toan he thong, thong ke theo loai link toan he thong, thong ke theo ngay trong tuan toan he thong, thong ke theo nguon UTM toan he thong, thong ke theo phuong tien UTM toan he thong, khach moi vs khach quay lai toan he thong, thong ke theo dich toan he thong, thong ke chat luong traffic theo quoc gia va host nguon (traffic_by_country, traffic_by_referrer_host).", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/events": {"get": {"summary": "40 events gan nhat", "description": "View/click moi nhat kem slug/title.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/system": {"get": {"summary": "Thong tin he thong", "description": "Version, uptime, dung luong DB, tong link/events, base_path, nhip quet dich tu dong (auto_monitor_minutes) + luot quet nen gan nhat.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/security": {"get": {"summary": "Nhat ky bao mat", "description": "Tong so lan chan, ly do, 30 su kien gan nhat, so IP dang bi treo.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/export": {"get": {"summary": "Xuat JSON", "description": "Toan bo link (backup/chuyen may).", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}}, "/api/import": {"post": {"summary": "Nhap JSON", "description": "Nhan dang {links:[...]} nhu file export; tra so link da nhap.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ImportInput"}}}}}}, "/api/import-external": {"post": {"summary": "Nhap tu Bitly/Linktree", "description": "Nhan CSV export cua Bitly qua truong 'csv' (cot Link/Custom Link/Title/Destination URL/Status) hoac JSON Bitly API v4/generic qua 'links'; tao link truc tiep, giu back-half cu, toi da 100 dong/luot.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ExternalImportInput"}}}}}}, "/api/bulk": {"post": {"summary": "Tao hang loat", "description": "Toi da 50 URL, moi dong 1 URL -> link truc tiep slug tu sinh.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BulkInput"}}}}}}, "/api/links/bulk-action": {"post": {"summary": "Thao tac hang loat", "description": "Ap 1 thao tac cho toi da 100 link: enable/disable/add_tags/remove_tags/set_folder/clear_folder. Co tinh KHONG co bulk delete (tranh xoa nham link that).", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BulkActionInput"}}}}}}, "/api/slugify": {"post": {"summary": "Sinh slug", "description": "Bo dau tieng Viet, tra slug tu title.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/SlugifyInput"}}}}}}, "/api/keys": {"get": {"summary": "Danh sach API key", "description": "Chi tra id/name/last_used — khong bao gio tra lai plaintext key.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}, "post": {"summary": "Tao API key", "description": "Plaintext key CHI HIEN 1 LAN trong response nay; server chi luu sha256.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"201": {"description": "Key moi (plaintext 1 lan)", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiKeyCreated"}}}}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ApiKeyInput"}}}}}}, "/api/keys/{id}": {"delete": {"summary": "Thu hoi API key", "description": "Key bi thu hoi se bi chan ngay.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "Da thu hoi"}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}, "parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "integer"}}]}}, "/api/bio": {"get": {"summary": "Danh sach trang bio", "description": "Cac trang /b/<slug> kieu Linktree.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}}, "post": {"summary": "Tao trang bio", "description": "Truong: title, slug; tuy chon subtitle, avatar_text.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"201": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}, "400": {"description": "Loi", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BioPageInput"}}}}}}, "/api/bio/{id}": {"put": {"summary": "Sua trang bio", "description": "Chi gui cac truong muon doi.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}, "requestBody": {"required": false, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BioPageInput"}}}}}, "delete": {"summary": "Xoa trang bio", "description": "Xoa ca trang va toan bo nut cua no.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "Da xoa"}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}}}, "/api/bio/{id}/items": {"post": {"summary": "Them nut bio", "description": "Truong: label, url; tuy chon icon, sort_order, enabled.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"201": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}, "400": {"description": "Loi", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}, "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BioItemInput"}}}}}}, "/api/bio/items/{id}": {"put": {"summary": "Sua nut bio", "description": "Chi gui cac truong muon doi.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}}, "requestBody": {"required": false, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/BioItemInput"}}}}}, "delete": {"summary": "Xoa nut bio", "description": "Xoa 1 nut khoi trang bio.", "security": [{"ApiKeyAuth": []}, {"AdminToken": []}], "responses": {"200": {"description": "Da xoa"}, "401": {"description": "Thieu/sai token hoac key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}}}, "/l/{slug}": {"get": {"summary": "Trang cau / link truc tiep", "description": "Nguoi that: trang cau hoac 302 thang. Bot preview MXH: chi nhan the OG. Bot xau: 403.", "security": [], "responses": {"200": {"description": "Trang cau HTML"}, "302": {"description": "Chuyen toi dich"}, "403": {"description": "Bot bi chan"}, "404": {"description": "Khong co link"}}}}, "/out/{slug}": {"get": {"summary": "Chuyen ra dich", "description": "Chi nguoi that duoc 302; moi bot deu 403; khong dem click bot. V43: dich quang cao (Monetag) bat buoc token click ky HMAC tu trang cau + cooldown 45s — click khong token/trung se bi dua ve trang cau, khong dem va khong cham dich quang cao.", "security": [], "responses": {"302": {"description": "Chuyen toi dich"}, "403": {"description": "Bot bi chan"}, "404": {"description": "Khong co link"}}}}, "/b/{slug}": {"get": {"summary": "Trang bio cong khai", "description": "Trang Linktree tren domain cua ban; bam nut dem click roi moi chuyen.", "security": [], "responses": {"200": {"description": "Trang bio HTML"}, "404": {"description": "Khong co trang"}}}}}, "components": {"securitySchemes": {"ApiKeyAuth": {"type": "apiKey", "in": "header", "name": "X-API-Key", "description": "Key tao trong admin (trang API Keys). Chi hien plaintext 1 lan luc tao."}, "AdminToken": {"type": "apiKey", "in": "header", "name": "X-Admin-Token", "description": "ADMIN_TOKEN trong .env cua server."}}, "schemas": {"Error": {"type": "object", "properties": {"error": {"type": "string"}}}, "Link": {"type": "object", "properties": {"id": {"type": "integer"}, "slug": {"type": "string"}, "title": {"type": "string"}, "destination": {"type": "string", "format": "uri"}, "link_type": {"type": "string", "enum": ["bridge", "direct"]}, "share_url": {"type": "string", "format": "uri"}, "active": {"type": "boolean"}, "clicks": {"type": "integer"}, "views": {"type": "integer"}}}, "LinkInput": {"type": "object", "properties": {"title": {"type": "string"}, "slug": {"type": "string"}, "destination": {"type": "string", "format": "uri"}, "link_type": {"type": "string", "enum": ["bridge", "direct"]}, "description": {"type": "string"}, "image": {"type": "string"}, "dest2": {"type": "string"}, "dest3": {"type": "string"}, "weight1": {"type": "integer"}, "weight2": {"type": "integer"}, "weight3": {"type": "integer"}, "targeting": {"type": "string", "description": "JSON rules country/device/referrer/browser/os (match referrer = chuoi con trong Referer, browser/os theo UA)"}, "utm_source": {"type": "string"}, "utm_medium": {"type": "string"}, "utm_campaign": {"type": "string"}, "access_code": {"type": "string"}, "max_clicks": {"type": "integer"}, "starts_at": {"type": "string"}, "expires_at": {"type": "string"}, "active_hours": {"type": "string", "example": "08:00-22:00"}, "active_days": {"type": "string", "example": "1,2,3,4,5"}, "deep_link": {"type": "string", "example": "fb://profile/123"}, "deep_link_auto": {"type": "boolean"}, "webhook_url": {"type": "string"}, "webhook_secret": {"type": "string"}, "pixel_id": {"type": "string"}, "ga_id": {"type": "string"}, "tags": {"type": "string"}, "folder": {"type": "string"}, "note": {"type": "string"}, "active": {"type": "boolean"}, "fallback_url": {"type": "string", "format": "uri", "description": "Dich du phong khi link chet (tat/het han/cham tran) — nguoi that se 302 toi day thay vi trang chet"}, "auto_fallback": {"type": "boolean", "description": "Bat = nguoi that se 302 toi fallback_url khi lan kiem tra dich gan nhat bao chet; tat = van di dich goc"}, "auto_monitor": {"type": "boolean", "description": "Bat = luong nen tu quet dich link nay theo nhip DOLINK_AUTO_CHECK_MINUTES (mac dinh 60 phut) va gui canh bao webhook khi dich moi chet hoac sap het han; tat = chi quet khi bam nut tay"}, "auto_optimize": {"type": "boolean"}}}, "ImportInput": {"type": "object", "required": ["links"], "properties": {"links": {"type": "array", "items": {"$ref": "#/components/schemas/LinkInput"}}}}, "ExternalImportInput": {"type": "object", "properties": {"csv": {"type": "string", "description": "Text CSV export tu Bitly/Linktree (cot Link/Custom Link/Title/Destination URL/Status)"}, "links": {"type": "array", "items": {"type": "object"}, "description": "Danh sach JSON kieu Bitly API v4 (long_url/title/tags/archived) hoac generic (destination/title/slug)"}}}, "BulkInput": {"type": "object", "required": ["urls"], "properties": {"urls": {"type": "array", "items": {"type": "string", "format": "uri"}, "maxItems": 50}}}, "BulkActionInput": {"type": "object", "required": ["ids", "action"], "properties": {"ids": {"type": "array", "items": {"type": "integer"}, "maxItems": 100}, "action": {"type": "string", "enum": ["enable", "disable", "add_tags", "remove_tags", "set_folder", "clear_folder"]}, "tags": {"type": "string", "description": "Chuoi tags cach nhau boi dau phay, chi dung cho add_tags/remove_tags"}, "folder": {"type": "string", "description": "Ten thu muc dich, chi dung cho set_folder"}}}, "SlugifyInput": {"type": "object", "required": ["title"], "properties": {"title": {"type": "string"}}}, "ApiKeyInput": {"type": "object", "properties": {"name": {"type": "string"}}}, "ApiKeyCreated": {"type": "object", "properties": {"id": {"type": "integer"}, "name": {"type": "string"}, "key": {"type": "string", "description": "Plaintext — CHI HIEN 1 LAN, luu ngay lai"}}}, "BioPageInput": {"type": "object", "properties": {"title": {"type": "string"}, "slug": {"type": "string"}, "subtitle": {"type": "string"}, "avatar_text": {"type": "string"}}}, "BioItemInput": {"type": "object", "properties": {"label": {"type": "string"}, "url": {"type": "string", "format": "uri"}, "icon": {"type": "string"}, "sort_order": {"type": "integer"}, "enabled": {"type": "boolean"}}}}}}