Webhook
Webhooks သည် သင့် s.id account မှ event များကို သင့် server သို့ တိုက်ရိုက်ပို့ပေးသည်။ Dashboard > Developer > Webhooks တွင် endpoint ကို စာရင်းသွင်းပြီး လိုအပ်သော event များကို ရွေးပါ။
Event နှင့် header များ
| Peristiwa | ပို့သည့်အချိန် |
|---|---|
link.created | Dicetuskan apabila pautan baharu dicipta |
link.updated | Dicetuskan apabila URL atau tajuk pautan diubah |
link.archived | Dicetuskan apabila pautan diarkibkan |
link.clicked | Dicetuskan pada setiap pengalihan (peristiwa setiap klik) |
microsite.published | Dicetuskan apabila microsite diterbitkan |
qr.scanned | Dicetuskan apabila kod QR diimbas |
| Pengepala | တန်ဖိုး |
|---|---|
X-SID-Event | Event အမည် (ဥပမာ link.created) |
X-SID-Signature | sha256=<hmac-hex> |
X-SID-Delivery-ID | ပို့ခြင်းတစ်ခုစီအတွက် ထူးခြားသော ID |
User-Agent | s.id-Webhooks/1.0 |
json
{
"event": "link.created",
"link": {
"id": 123,
"short": "[your-alias]",
"short_url": "https://s.id/[your-alias]",
"long_url": "https://example.com/long-url",
"title": "My Link",
"created": "2026-06-22T10:00:00Z"
},
"timestamp": "2026-06-22T10:00:00Z"
}ပို့ခြင်း
- POST နှင့် Content-Type: application/json ဖြင့် ပို့သည်။
- event တစ်ခုလျှင် အများဆုံး ၃ ကြိမ် ကြိုးစားသည်၊ ၀၊ ၅ နှင့် ၃၀ စက္ကန့် နောက်ကျသည်။
- event ၅ ခု ဆက်တိုက် မအောင်မြင်ပါက webhook ကို ပိတ်လိုက်သည်။
- Test ခလုတ်သည် နမူနာ payload ကို ပို့ပြီး မှတ်တမ်းကို Deliveries တွင် ကြည့်နိုင်သည်။
Signature စစ်ဆေးခြင်း
ပို့သည့်အရာတိုင်းကို သင့် webhook secret ဖြင့် raw body ပေါ်တွင် HMAC-SHA256 ဖြင့် လက်မှတ်ထိုးထားသည်။ payload ကို မပြုလုပ်မီ ပြန်တွက်ပါ။
javascript
const crypto = require('node:crypto');
function verifySignature(secret, rawBody, sigHeader) {
if (typeof sigHeader !== 'string' || !sigHeader.startsWith('sha256=')) {
return false;
}
const expected = 'sha256=' +
crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
const receivedBuffer = Buffer.from(sigHeader, 'utf8');
const expectedBuffer = Buffer.from(expected, 'utf8');
return receivedBuffer.length === expectedBuffer.length &&
crypto.timingSafeEqual(receivedBuffer, expectedBuffer);
}