Webhook
Webhook memberikan notifikasi HTTP POST waktu nyata ketika tugas asinkron latar belakang selesai, seperti penerbitan postingan yang berhasil, kegagalan, atau pengiriman balasan.
📌 Titik Akhir
Section titled “📌 Titik Akhir”| Metode | Jalur | Deskripsi | Cakupan yang Diperlukan |
|---|---|---|---|
POST | /v1/brand/webhooks/subscriptions | Mendaftarkan titik akhir webhook baru | webhooks:write atau * |
GET | /v1/brand/webhooks/subscriptions | Menampilkan langganan webhook yang terdaftar | webhooks:read atau * |
DELETE | /v1/brand/webhooks/subscriptions/{id} | Menghapus langganan webhook | webhooks:write atau * |
🔔 Tipe Peristiwa yang Didukung
Section titled “🔔 Tipe Peristiwa yang Didukung”| Nama Peristiwa | Kondisi Pemicu |
|---|---|
sns.publish.succeeded | Postingan berhasil diterbitkan ke jaringan sosial target |
sns.publish.failed | Penerbitan postingan gagal (termasuk kode kesalahan dan kelayakan percobaan ulang) |
sns.publish.blocked_entitlement | Penerbitan diblokir karena batas kuota atau paket yang kedaluwarsa |
sns.reply.succeeded | Komentar balasan berhasil diposting |
sns.reply.failed | Pengiriman komentar balasan gagal |
sns.provider.notification_received | Webhook waktu nyata diterima dari penyedia SNS eksternal |
📦 Contoh Payload Webhook (sns.publish.succeeded)
Section titled “📦 Contoh Payload Webhook (sns.publish.succeeded)”{ "event_id": "evt_01jm8za2example", "event_type": "sns.publish.succeeded", "schema_version": 1, "occurred_at": "2026-08-16T03:30:00Z", "producer": "ankk.sns", "brand_ref": "brand_01jm8v4k9example", "idempotency_key": "launch-2026-001", "trace_id": "trc_9a8b7c6d", "data": { "content_id": "content_01jm8za2example", "publish_job_id": "job_01jm8za2jobexample", "sns_type": "instagram", "connection_id": "conn_01jm8x9k2example", "provider_post_id": "18029384756102938", "permalink": "https://www.instagram.com/p/C-example/" }}🔐 Verifikasi Tanda Tangan (HMAC SHA256)
Section titled “🔐 Verifikasi Tanda Tangan (HMAC SHA256)”Permintaan webhook menyertakan header verifikasi khusus:
Social-Webhook-Signature: Payload tanda tangan (t=1723780000,v1=hex_signature)Social-Webhook-Timestamp: Stempel waktu Unix dalam detikSocial-Webhook-Id: Pengenal peristiwa
Verifikasi Node.js (Crypto)
Section titled “Verifikasi Node.js (Crypto)”import crypto from 'node:crypto';
export function verifyWebhookSignature( rawBody: string, signatureHeader: string, timestampHeader: string, secret: string): boolean { const signedPayload = `${timestampHeader}.${rawBody}`; const expectedSignature = crypto .createHmac('sha256', secret) .update(signedPayload) .digest('hex');
return crypto.timingSafeEqual( Buffer.from(signatureHeader), Buffer.from(expectedSignature) );}Verifikasi Python (hmac)
Section titled “Verifikasi Python (hmac)”import hmacimport hashlib
def verify_webhook_signature(raw_body: bytes, signature: str, timestamp: str, secret: str) -> bool: signed_payload = f"{timestamp}.".encode('utf-8') + raw_body expected = hmac.new(secret.encode('utf-8'), signed_payload, hashlib.sha256).hexdigest() return hmac.compare_digest(signature, expected)[!CAUTION] Verifikasi tanda tangan harus menggunakan raw request body (body permintaan mentah) yang belum di-parse.