Webhooks
Events, payloads, retries, and signature checks in PHP, Node and Python.
What gets sent
A brand admin adds a webhook in SocialKuy under Brand → Integrations with an https address and the events it wants:
post.published,post.failed,post.uncertain(the connection dropped during the last step; someone checks the network in the app), once per channel;post.review_requested,post.approved,post.rejected;channel.needs_reconnect,channel.reconnected;comment.received: new comments on Facebook, Instagram and Threads, only for webhooks created with the consent to share network data.
Events about YouTube and TikTok are never sent.
The request
Each delivery is a POST with a JSON body:
{
"id": "evt_6b0c8a3e-...",
"event": "post.published",
"occurred_at": "2026-11-02T02:00:04Z",
"brand": {"id": 7, "slug": "kopi-senja", "name": "Kopi Senja"},
"data": {"post": {"id": 1042, "status": "scheduled", "...": "..."}, "target": {"channel_id": 12, "status": "published", "...": "..."}}
}
and three headers:
SocialKuy-Event: the event name.SocialKuy-Delivery: the delivery id. It stays the same on every retry and when someone presses "Send again", so use it to ignore deliveries you already handled.SocialKuy-Signature:t=<unix time>,v1=<signature>.
The full payload of every event is in the API reference.
Answering
Answer with any 2xx within 10 seconds; do the real work afterwards. Anything else is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours, then the delivery counts as failed. A 410 Gone answer turns the webhook off at once. A webhook that fails for 3 days without a single success turns off as well, and the brand admins are told. Redirects are not followed.
Deliveries may arrive out of order: sort by occurred_at.
Checking the signature
The signature is an HMAC-SHA256 of t + "." + body with the webhook's signing secret, written in hex. Always check it against the raw body exactly as it arrived, before parsing the JSON, and refuse old timestamps so a captured request cannot be sent again later.
PHP:
function verify_signature(string $payload, string $header, string $secret, int $tolerance = 300): bool
{
$parts = [];
foreach (explode(',', $header) as $item) {
[$key, $value] = array_pad(explode('=', trim($item), 2), 2, '');
$parts[$key] = $value;
}
if (! isset($parts['t'], $parts['v1']) || ! ctype_digit($parts['t']) || abs(time() - (int) $parts['t']) > $tolerance) {
return false;
}
return hash_equals(hash_hmac('sha256', $parts['t'].'.'.$payload, $secret), $parts['v1']);
}
// $payload = file_get_contents('php://input');
Node:
const crypto = require('node:crypto');
function verifySignature(payload, header, secret, tolerance = 300) {
const parts = Object.fromEntries(header.split(',').map((item) => item.trim().split('=')));
const timestamp = Number(parts.t);
if (!parts.t || !parts.v1 || !Number.isInteger(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > tolerance) {
return false;
}
const expected = Buffer.from(crypto.createHmac('sha256', secret).update(`${parts.t}.${payload}`).digest('hex'));
const given = Buffer.from(parts.v1);
return expected.length === given.length && crypto.timingSafeEqual(expected, given);
}
// Express: app.post('/hook', express.raw({ type: 'application/json' }), (req, res) => verifySignature(req.body.toString('utf8'), ...))
Python:
import hashlib
import hmac
import time
def verify_signature(payload: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
parts = dict(item.strip().split("=", 1) for item in header.split(",") if "=" in item)
timestamp = parts.get("t", "")
if not timestamp.isdigit() or "v1" not in parts or abs(time.time() - int(timestamp)) > tolerance:
return False
expected = hmac.new(secret.encode(), timestamp.encode() + b"." + payload, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])
# Flask: verify_signature(request.get_data(), request.headers["SocialKuy-Signature"], secret)
Testing
Send test event in SocialKuy sends a ping to the address. The delivery log next to it shows every delivery of the last 30 days with the answer you gave (the first 1 KB), and lets you send one again. Payloads are removed after 7 days.
If the secret leaks, make a new one under the webhook's menu; the old one stops working at once.