مُختصر روابط بسيط

توثيق API

JSON API لإنشاء روابط قصيرة مع 301 دائم وصفحة وسطية اختيارية و QR بصيغة PNG.

نظرة عامة على API

الرابط الأساسي: https://pth.bz

المسار

POST https://pth.bz/api/shorten

Content-Type: application/json

الطلب

Body JSON:

{
  "url": "https://example.com/landing?utm_source=newsletter"
}

الاستجابة

200 OK:

{
  "short_url_301": "https://pth.bz/AbC1234",
  "short_url_js": "https://pth.bz/i/AbC1234",
  "qr_301_png_url": "https://pth.bz/?qr=AbC1234",
  "qr_js_png_url": "https://pth.bz/?qi=AbC1234"
}
حالات أخرى
  • 400 - طلب خاطئ.
  • 405 - استخدم POST.
  • 429 - طلبات كثيرة.
  • 500 - خطأ داخلي.

اختيار التحويل

301 (افتراضي)

تحويل دائم سريع: /CODE

صفحة وسطية (مكافحة الروبوتات)

خطوة JS قصيرة مع إخفاء المُحيل: /i/CODE

رموز QR (PNG)

  • For 301: /?qr=CODE
  • For interstitial: /?qi=CODE
  • حجم اختياري بالبكسل: (200–2048) &px=640
<img src="https://pth.bz/?qr=AbC1234&px=640" alt="QR" />

استجابات الأخطاء

{
  "error": "Too many requests"
}

القيود والقواعد

  • الحد: 30 طلبًا / 10 دقائق / IP.
  • http:// و https:// فقط.
  • أقصى طول للرابط: 2000 حرفًا.
  • JSON فقط: Content-Type: application/json.

أمثلة

curl
curl -X POST "https://pth.bz/api/shorten" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'
JavaScript (fetch)
const res = await fetch('https://pth.bz/api/shorten', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ url: 'https://example.com' })
});
const data = await res.json();
console.log(data.short_url_301, data.short_url_js);
Python (requests)
import requests

r = requests.post('https://pth.bz/api/shorten', json={'url': 'https://example.com'})
print(r.status_code, r.json())

SDK

Python SDK

مكتبة بايثون الرسمية للعمل مع مُختصر روابط بسيط.

Install
pip install pthbz
Quick start (sync)
from pthbz import PthBzClient

client = PthBzClient(base_url="https://pth.bz")
res = client.shorten("https://example.com/landing?utm_source=newsletter")
print(res.short_url_301)   # https://pth.bz/AbC1234
print(res.short_url_js)    # https://pth.bz/i/AbC1234
print(res.qr_301_png_url)  # https://pth.bz/?qr=AbC1234
print(res.qr_js_png_url)   # https://pth.bz/?qi=AbC1234
client.close()
Async variant
import asyncio
from pthbz import AsyncPthBzClient

async def main():
    async with AsyncPthBzClient(base_url="https://pth.bz") as client:
        res = await client.shorten("https://example.com")
        print(res.short_url_301)

asyncio.run(main())
يتحقق التحقق المحلي من الروابط وفق قواعد الخادم: فقط http/https، دون معلومات مستخدم؛ مسموح localhost وIP بلا نقطة؛ IDN → punycode.