Documentation API
API JSON pour créer des liens courts avec 301 permanent, page intermédiaire optionnelle et QR PNG.
Présentation de l'API
URL de base : https://pth.bz
Endpoint
POST https://pth.bz/api/shorten
Content-Type: application/json
Requête
Body JSON:
{
"url": "https://example.com/landing?utm_source=newsletter"
}
Réponse
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"
}
Autres statuts
- 400 - JSON/URL invalide.
- 405 - Utilisez POST.
- 429 - Trop de requêtes.
- 500 - Erreur interne.
Choisir la redirection
301 (par défaut)
Redirection permanente rapide : /CODE
Interstitielle (anti-bot)
Étape JS courte, référent masqué : /i/CODE
QR codes (PNG)
- For 301:
/?qr=CODE
- For interstitial:
/?qi=CODE
- Taille optionnelle en px : (200–2048)
&px=640
<img src="https://pth.bz/?qr=AbC1234&px=640" alt="QR" />
Réponses d'erreur
{
"error": "Too many requests"
}
Limites et règles
- Limite : 30 requêtes / 10 min / IP.
- Uniquement http:// et https://.
- Longueur maxi de l'URL : 2000 caractères.
- JSON uniquement : définissez Content-Type: application/json.
Exemples
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
Bibliothèque Python officielle pour utiliser Raccourcisseur d'URL simple.
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())
La validation locale des URL reflète les règles du serveur : http/https uniquement, sans userinfo ; localhost et IP sans point autorisés ; IDN → punycode.