Autentikasi
Dua cara autentikasi dengan API s.id — API key untuk server-ke-server, OAuth 2.0 untuk bertindak atas nama pengguna.
API Key
API key dipakai buat autentikasi integrasi server-ke-server. Buat satu di Dashboard → Developer → API Keys, pilih scope kamu, lalu kirim sebagai token Bearer.
Header Otorisasi
Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxContoh permintaan
curl https://api.s.id/v2/links \
-H "Authorization: Bearer sk_live_..."
Scope yang tersedia
links:readList and read linkslinks:writeCreate and update links (create, edit, restore)links:archiveArchive linkslinks:analyticsRead per-link click statistics and lifetime countsqr:readRead QR code settings (global and per-link)qr:writeCustomize QR code settings (global and per-link)user:readRead the authenticated user profile and account quotamicrosites:readRead micrositesmicrosites:writeCreate, update and manage components of micrositesmicrosites:deleteDelete microsites and their components- •Kunci diawali sk_live_ dan hanya ditampilkan sekali saat pembuatan.
- •Minta scope seminimal mungkin yang integrasimu butuhkan.
- •Cabut kunci segera jika dikompromi — buat yang baru.
- •Jangan pernah mengekspos API key di sisi klien (browser, aplikasi mobile).
OAuth 2.0
Gunakan alur authorization-code untuk bertindak atas nama pengguna s.id. Aplikasi kamu arahkan pengguna ke s.id buat persetujuan, lalu tukar kodenya dengan token akses.
Alur otorisasi
- 1Alihkan pengguna
GET https://api.s.id/oauth/authorize ?client_id=YOUR_CLIENT_ID &redirect_uri=https://yourapp.com/callback &response_type=code &scope=links:read links:write &state=RANDOM_STATE &code_challenge=CODE_CHALLENGE &code_challenge_method=S256 - 2Tukarkan kode dengan token
POST https://api.s.id/oauth/token Content-Type: application/x-www-form-urlencoded grant_type=authorization_code &code=AUTH_CODE &redirect_uri=https://yourapp.com/callback &client_id=YOUR_CLIENT_ID &client_secret=YOUR_CLIENT_SECRET &code_verifier=CODE_VERIFIER - 3Gunakan access token
GET https://api.s.id/oauth/userinfo Authorization: Bearer ACCESS_TOKEN
PKCE (S256) wajib digunakan untuk public client — aplikasi tanpa client secret (SPA, mobile, CLI) — dan opsional untuk confidential client. Tambahkan code_challenge dan code_challenge_method pada langkah 1, serta code_verifier pada langkah 2. Access token yang dihasilkan bekerja seperti API key pada endpoint /v2 mana pun, sesuai scope yang diberikan pengguna.