Webhooks Integration Guide
Receive real-time HTTP POST notifications when people enter your giveaway, complete tasks, or finish all entries.
Plan required: Enterprise.
Overview
SweepWidget provides two ways to receive real-time event data from your giveaways:
- Server-side webhooks – HTTP POST requests from our server to yours. They work on embedded widgets and hosted landing pages. Best for backend workflows like CRM syncing, email triggers and database updates.
- Client-side JavaScript callbacks – browser events fired on the page where the widget is loaded. Best for frontend actions like firing tracking pixels, showing custom UI, or triggering analytics events.
Both use the same three event names and similar data. The differences are listed under Events.
On this page:
- Setup
- Events
- Payload Format
- Request Headers
- Signature Verification
- JavaScript Callbacks
- Signing Secret
- Troubleshooting
Setup
Server-side webhooks
- In the left menu, click API Integrations. In the E-commerce & Automation section, click Webhooks.
- Enter your endpoint URL in Webhook URL (it must start with https://) and click Save.
- Copy the Secret Key under Signing Secret to verify webhook signatures on your server.
Click Send Test to send a test request and confirm your endpoint receives it. The test request has the event name test.
Note: webhooks are set per brand. They fire for every giveaway in the brand where you saved them. If you manage several brands, set up webhooks in each brand.
JavaScript callbacks
No dashboard configuration needed. Add an event listener to the page where your SweepWidget is embedded. See JavaScript Callbacks below.
Events
All events fire automatically. There is no per-event toggle.
| Event | Fires when |
|---|---|
| entry_submitted | An entrant successfully submits the entry form (email, name, etc.). It fires again if a returning entrant submits the form again |
| task_completed | An entrant completes a bonus entry task (follow, visit, share, etc.) |
| all_entries_completed | An entrant has completed every available task |
Differences between webhooks and JS callbacks:
- Webhook all_entries_completed is sent only right after an entrant completes their last bonus task. If your giveaway has no bonus entry methods, it is never sent.
- JS all_entries_completed also fires when an entrant who already finished everything opens the giveaway again, so it can fire more than once for the same person.
Payload Format
Webhooks wrap the data in an event + data + timestamp envelope. JS callbacks provide the data directly in e.detail, and add a timestamp field to it.
entry_submitted
{
"event": "entry_submitted",
"data": {
"competition_id": "12345",
"competition_url": "my-giveaway",
"user": {
"email": "[email protected]",
"name": "Jane Smith",
"phone": "+1234567890",
"birthday": "1990-01-15"
},
"custom_fields": [
{
"entry_id": "101",
"field_type": "text_input",
"label": "Company Name",
"value": "Acme Corp"
}
],
"entries": 5,
"referral_url": "https://sweepwidget.com/c/my-giveaway-abc123"
},
"timestamp": "2026-03-04T12:00:00+00:00"
}
task_completed
{
"event": "task_completed",
"data": {
"competition_id": "12345",
"competition_url": "my-giveaway",
"user": {
"email": "[email protected]",
"name": "Jane Smith"
},
"task": {
"entry_id": "67",
"entry_method": "visit_a_page",
"entry_group_id": "3"
},
"entries": 10,
"remaining_tasks": 2
},
"timestamp": "2026-03-04T12:01:00+00:00"
}
entry_method is SweepWidget’s internal name for the entry method (for example visit_a_page).
all_entries_completed
{
"event": "all_entries_completed",
"data": {
"competition_id": "12345",
"competition_url": "my-giveaway",
"user": {
"email": "[email protected]",
"name": "Jane Smith"
},
"entries": 25
},
"timestamp": "2026-03-04T12:02:00+00:00"
}
test (Send Test button)
{
"event": "test",
"data": {
"message": "Webhook configured successfully.",
"website_id": "123"
},
"timestamp": "2026-03-04T12:00:00+00:00"
}
Request Headers
| Header | Description |
|---|---|
| Content-Type | application/json |
| X-SweepWidget-Signature | HMAC-SHA256 signature of the payload body, prefixed with sha256= |
| X-SweepWidget-Event | The event name (e.g. entry_submitted, or test) |
| User-Agent | SweepWidget-Webhook/1.0 |
Signature Verification
Always verify the X-SweepWidget-Signature header to confirm the request came from SweepWidget. Compute an HMAC-SHA256 hash of the raw request body using your signing secret and compare it to the signature in the header.
PHP
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_SWEEPWIDGET_SIGNATURE'] ?? '';
$secret = 'whsec_your_signing_secret';
$expected = 'sha256=' . hash_hmac('sha256', $payload, $secret);
if (!hash_equals($expected, $signature)) {
http_response_code(401);
exit('Invalid signature');
}
$event = json_decode($payload, true);
// Process the event...
Node.js
const crypto = require('crypto');
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['x-sweepwidget-signature'] || '';
const secret = 'whsec_your_signing_secret';
const expected = 'sha256=' + crypto
.createHmac('sha256', secret)
.update(req.body)
.digest('hex');
if (signature !== expected) {
return res.status(401).send('Invalid signature');
}
const event = JSON.parse(req.body);
// Process the event...
res.sendStatus(200);
});
JavaScript Callbacks
SweepWidget fires browser events when someone enters your giveaway, completes a task, or finishes all entries. On embedded widgets the embed script relays them from the iframe to your page. On hosted landing pages they fire on the page’s window.
No dashboard configuration is required. Add a listener to the page where your widget is embedded.
Method 1: Individual event listeners
Listen for specific events by name. The event data is in e.detail.
window.addEventListener('sweepwidget.entry_submitted', function(e) {
console.log(e.detail.user.email); // "[email protected]"
console.log(e.detail.user.name); // "Jane Smith"
console.log(e.detail.entries); // 5
console.log(e.detail.custom_fields); // [{entry_id, field_type, label, value}]
console.log(e.detail.referral_url); // "https://sweepwidget.com/c/..."
});
window.addEventListener('sweepwidget.task_completed', function(e) {
console.log(e.detail.task.entry_method); // "visit_a_page"
console.log(e.detail.remaining_tasks); // 2
});
window.addEventListener('sweepwidget.all_entries_completed', function(e) {
console.log(e.detail.entries); // 25
});
Method 2: Catch-all event listener (embedded widgets only)
On a page with an embedded widget, you can listen for all SweepWidget events with one listener. The event name and data are in e.detail.event and e.detail.data. This catch-all event is not fired on hosted landing pages; use Method 1 or 3 there.
window.addEventListener('sweepwidget', function(e) {
console.log('Event:', e.detail.event); // "sweepwidget.entry_submitted"
console.log('Data:', e.detail.data); // {competition_id, user, entries, ...}
});
Method 3: Global callback function
Define a global function that is called for every event. This works even if you add it before the SweepWidget script loads.
window.SweepWidgetCallback = function(eventName, eventData) {
// eventName: "sweepwidget.entry_submitted"
// eventData: {competition_id, user, entries, custom_fields, ...}
console.log(eventName, eventData);
};
Extra event: instant win
sweepwidget.instant_win fires when instant-win results are shown to an entrant. e.detail contains competition_id and results. This event fires on all plans.
Example: Fire a Meta/Facebook pixel event on entry
window.addEventListener('sweepwidget.entry_submitted', function(e) {
fbq('track', 'Lead', {
content_name: e.detail.competition_url,
value: e.detail.entries,
currency: 'USD'
});
});
Example: Google Analytics event on entry
window.addEventListener('sweepwidget.entry_submitted', function(e) {
gtag('event', 'giveaway_entry', {
competition_id: e.detail.competition_id
});
});
Embedded widgets: events are sent from the iframe to the parent page with postMessage. The SweepWidget embed script relays them as events on the parent window, so your listeners work without extra setup.
Signing Secret
A signing secret is created automatically the first time you open the Webhooks page on an Enterprise plan. To replace it, click Regenerate next to Secret Key and confirm.
Important: regenerating the secret immediately invalidates the old one. Update your server with the new secret right away to avoid rejected webhooks.
Troubleshooting
| Issue | Solution |
|---|---|
| Not receiving webhooks | Confirm your URL starts with https:// and your endpoint returns a 2xx status code. Click Send Test to check. Check that you saved the webhook in the same brand as the giveaway. |
| No all_entries_completed webhook | It is sent only after an entrant completes their last bonus task. Giveaways without bonus entry methods never send it. |
| Signature mismatch | Hash the raw request body (not a parsed/re-serialized version). Check that your secret matches the one shown in settings. |
| Timeouts | SweepWidget waits up to 5 seconds to connect and 10 seconds in total. Failed deliveries are not retried. Return a 200 immediately and process the data asynchronously. |
| JS callbacks not firing (embedded) | Use the SweepWidget script embed code, not a raw iframe. The embed script relays the events. Add your event listeners before the embed script loads. |
| JS callbacks not firing (hosted) | On hosted landing pages, events fire on the page’s window; the catch-all “sweepwidget” event does not. Verify your account is on an Enterprise plan. |