Skip to content

สร้างลิงก์ย่อ POST ​

สร้างลิงก์ย่อ (short URL) จาก URL ปลายทาง เพื่อใช้แนบในข้อความ SMS และนับจำนวนคลิกได้

Authorization ​

ใช้ API Key (การยืนยันตัวตน) — ส่ง header Authorization: Bearer <API_KEY> (API Key ขึ้นต้นด้วย smsk_)

HTTP Request ​

http
POST https://public-api.smsup-plus.com/shorten/create

Content Type ​

application/json

Parameter Description ​

PropertyTypeRequiredDescription
urlstringRequiredURL ปลายทาง ต้องขึ้นต้นด้วย http:// หรือ https://
messageIdstringOptionalรหัสอ้างอิงของคุณเอง (เช่น รหัสข้อความ) เก็บไว้คู่กับลิงก์ จะแสดงกลับใน สถิติลิงก์

Response Description ​

PropertyTypeDescription
statusnumber200 เมื่อสำเร็จ
data.shortCodestringรหัสลิงก์ย่อ 8 ตัวอักษร (a-z, A-Z, 0-9)
data.shortUrlstringลิงก์ย่อพร้อมใช้งาน (โดเมนลิงก์ย่อ + shortCode)
data.originalstringURL ปลายทางที่ส่งมา

ตัวอย่าง Request ​

bash
curl -X POST 'https://public-api.smsup-plus.com/shorten/create' \
  -H 'Authorization: Bearer <API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
    "url": "https://www.example.com/promotion?utm_source=sms",
    "messageId": "PROMO-2026-11"
  }'
js
const res = await fetch('https://public-api.smsup-plus.com/shorten/create', {
  method: 'POST',
  headers: { Authorization: 'Bearer <API_KEY>', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    url: 'https://www.example.com/promotion?utm_source=sms',
    messageId: 'PROMO-2026-11',
  }),
})
console.log(await res.json())

ตัวอย่าง Response ​

json
{
  "status": 200,
  "data": {
    "shortCode": "aB3dE9xZ",
    "shortUrl": "https://c0c.me/aB3dE9xZ",
    "original": "https://www.example.com/promotion?utm_source=sms"
  }
}

Error ที่อาจเจอ ​

HTTPResponseสาเหตุ
400{"status":400,"description":"invalid request body"}body ไม่ใช่ JSON หรือไม่ได้ส่ง url
400{"status":400,"description":"URL must use http or https scheme"}url ไม่ได้ขึ้นต้นด้วย http:// หรือ https://
401{"error":"invalid api key"}API Key ไม่ถูกต้อง — ดู Error
500{"status":500,"description":"failed to create short URL"}ระบบสร้างลิงก์ไม่สำเร็จ ลองใหม่อีกครั้ง

TIP

ใช้ค่า shortUrl จาก response ตามที่ได้รับเสมอ (โดเมนในตัวอย่างเป็นเพียงตัวอย่าง) — เมื่อผู้รับกดลิงก์ ระบบจะพาไปยัง URL ปลายทางและนับคลิกให้อัตโนมัติ

INFO

ทุกครั้งที่เรียกจะได้ลิงก์ใหม่เสมอ แม้ส่ง url เดิมซ้ำ