Webhooks
Webhook आपके s.id अकाउंट के इवेंट सीधे आपके सर्वर तक भेजता है। Dashboard > Developer > Webhooks में endpoint रजिस्टर करें और ज़रूरी इवेंट चुनें।
Event और header
| इवेंट | कब भेजा जाता है |
|---|---|
link.created | नया लिंक बनने पर सक्रिय होता है |
link.updated | लिंक का URL या शीर्षक बदलने पर सक्रिय होता है |
link.archived | लिंक संग्रहित होने पर सक्रिय होता है |
link.clicked | हर रीडायरेक्ट पर सक्रिय होता है (प्रति क्लिक इवेंट) |
microsite.published | Microsite प्रकाशित होने पर सक्रिय होता है |
qr.scanned | QR कोड स्कैन होने पर सक्रिय होता है |
| हेडर | मान |
|---|---|
X-SID-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 के साथ भेजा जाता है।
- हर इवेंट के लिए अधिकतम 3 प्रयास, 0, 5 और 30 सेकंड के अंतराल पर।
- लगातार 5 असफल इवेंट के बाद webhook बंद कर दिया जाता है।
- Test बटन नमूना payload भेजता है, और इतिहास Deliveries में मिलता है।
सिग्नेचर सत्यापित करें
हर डिलीवरी आपके 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);
}