LuckLogic API
A JSON API over HTTPS. Create a campaign, generate printable codes, and redeem them from your own backend. Any language or framework that can make an HTTP request works. For Node.js there is also an official client, @lucklogic/node.
Your first redemption in five calls
Every call needs an API key, and keys are created in the portal, so
get a key first. Then follow the guide below. Every example is a real
request against https://api.lucklogic.dev and every response shown is what the
API returned.
Get an API key
There is no key until you create one. It takes a minute:
- Create an account at app.lucklogic.dev/signup. Signing up creates your workspace and makes you its admin. If a colleague already has a workspace, ask them to invite you instead.
- In the portal, open Settings. Only admins see the API keys section.
-
Under API keys, choose Create API key, give it a name and pick a mode:
sandbox for an
sk_test_key while you build, production for ansk_live_key when you go live. - Copy the key straight away. It is shown once; if you lose it, create a new one and revoke the old.
The curl examples on this page read the key from a shell variable, so set it once in your terminal and every example can be pasted as it is:
$ export KEY=sk_test_...
Check it works. A new workspace has no campaigns yet, so an empty list is the right answer:
curl https://api.lucklogic.dev/v1/campaigns -H "Authorization: Bearer $KEY"
{ "data": [] }
A 401 means the key is wrong or revoked. Campaigns you made in the portal
appear only for a key of the same mode: a sandbox campaign is invisible to an
sk_live_ key, and the other way round.
curl is not required. To try calls without writing code, open the
API reference, paste your key and use
Test Request on any endpoint. To use Postman or Insomnia, import
https://api.lucklogic.dev/v1/openapi.json and set the collection's
authorization to Bearer Token with your key.
Keys and authentication
Send your secret key as a bearer token on every request:
Authorization: Bearer sk_test_…. Bodies are JSON with
Content-Type: application/json.
Secret keys belong on your server only. Never put one in a browser or a mobile app: the consumer's code
goes to your backend, and your backend calls LuckLogic. For a browser-only page, use the widget with a
publishable key (pk_…) instead.
Sandbox and production
sk_test_ keys see sandbox campaigns, sk_live_ keys
see production campaigns. They never mix. Sandbox campaigns can be force-won and reset for testing. A
production campaign is activated once. Its code length and alphabet lock as soon as typed codes are
generated, because printed codes must stay redeemable. Its dates and prize quantities can still be changed
while it runs (see Campaign lifecycle); in production every such
change needs a reason and is written to the campaign's change log.
1Create a campaign
A campaign has a window and one or more prize tiers. Each tier has a quantity and a distribution:
even spreads its winning moments across the window,
late_stage keeps them in the last 30% of the campaign, and
uniform draws them at random. The optional
rate_limit
caps redemptions per participant.
curl https://api.lucklogic.dev/v1/campaigns \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{
"name": "Summer 2027",
"starts_at": "2027-06-01T00:00:00Z",
"ends_at": "2027-08-31T23:59:59Z",
"timezone": "Europe/London",
"rate_limit": { "max": 3, "window_seconds": 86400 },
"prize_tiers": [
{ "tier": "main", "name": "Trip for two", "quantity": 1, "distribution": "late_stage" },
{ "tier": "secondary", "name": "Festival weekend pass", "quantity": 500, "distribution": "even" }
]
}'
{
"id": "camp_f08438b7bbde40608d4c0830dae69f42",
"name": "Summer 2027",
"mode": "sandbox",
"status": "draft",
"timezone": "Europe/London",
"code_length": 10,
"prize_tiers": [
{ "tier": "main", "name": "Trip for two", "rank": 1, "quantity": 1, "distribution": "late_stage", ... },
{ "tier": "secondary", "name": "Festival weekend pass", "rank": 2, "quantity": 500, "distribution": "even", ... }
],
...
}
timezone is optional and defaults to your workspace's company timezone.
Timezones are IANA names such as Europe/London or
America/New_York; anything else is refused. Each tier can also set its own
window, a fixed claim_deadline after which the
prize is no longer awarded, and fulfilment (how the prize is handed over and
checked). See Campaigns in the
API reference.
2Generate codes
Codes are generated in the background. Ask for a volume, then poll the job until it is
ready. By default codes use the 28-character alphabet
ACDEFGHJKLMNPQRTUVWXYZ234679:
0 O 1 I 8 B 5 S never appear, so a smudged print cannot be misread. A campaign
created with "code_alphabet": "numeric" gets digit-only codes instead, which
need more length for the same volume. code_length is 5 to 16 characters
(default 10). Codes are stored only as keyed hashes.
curl https://api.lucklogic.dev/v1/campaigns/camp_f084.../generate \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{ "volume": 1000 }'
{ "job_id": "job_fc350e6574064a928f469679b4bf17e4", "status": "queued" }
{
"id": "job_fc350e6574064a928f469679b4bf17e4",
"status": "ready",
"format": "alphanumeric",
"progress": 100,
"volume": 1000,
"generated_count": 1000,
"code_length": 10,
"download_url": "https://….r2.cloudflarestorage.com/…/batches/….csv?X-Amz-…",
...
}
download_url is a signed link to a one-column CSV for the printer. It expires
after 15 minutes; poll the job again for a fresh link. For QR printing, send
"format": "qr_token" to get a token,url CSV whose
URLs scan straight to the hosted entry page.
Before going live, ask how the prizes would fall:
POST /v1/campaigns/{id}/simulate with an expected number of
entries and a pattern (steady, front_loaded or back_loaded) returns prizes won
per tier, prizes left at the end, overall odds and a timeline. It is read-only and runs on fresh random
schedules, so it never reveals the real one.
3Activate
Activation creates the hidden winning-moment schedule and makes the campaign live between
starts_at and ends_at. A production campaign can
be activated once.
curl -X POST https://api.lucklogic.dev/v1/campaigns/camp_f084.../activate -H "Authorization: Bearer $KEY"
{ "id": "camp_f084...", "status": "active", "activated_at": "2027-06-01T08:00:00.000Z", ... }
4Redeem a code
Your backend posts the code the consumer typed or scanned. Case, spaces and hyphens are ignored. Pass
participant_id, any opaque id from your own system, to enforce per-participant
limits; LuckLogic never needs a name or email. Send an Idempotency-Key so a
retried request can never redeem twice.
curl https://api.lucklogic.dev/v1/redemptions \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{ "campaign_id": "camp_f084...", "code": "km7rx-4q9cn", "participant_id": "crm_12345" }'
{
"id": "rdm_607ca30e8f214b8fa663aad6b2aa439d",
"campaign_id": "camp_f084...",
"outcome": "win",
"prize": { "tier": "secondary", "name": "Festival weekend pass" },
"claim_token": "clm_3t2vqKQdW801cKy0kQCVDhfS",
"participant_id": "crm_12345",
"redeemed_at": "2027-07-14T09:21:04.351Z"
}
{
"id": "rdm_ddc6ed6821c84ab5a3ab2461b6c501cf",
"campaign_id": "camp_f084...",
"outcome": "lose",
"prize": null,
"claim_token": null,
"participant_id": "crm_67890",
"redeemed_at": "2027-07-14T09:21:04.472Z"
}
outcome is win or
lose. Anything that is not a valid redemption comes back as an
error. Store the claim_token against your
user: it is how the prize is collected.
5Claims and fulfilment
Every win creates a claim. Its status moves through pending,
approved and fulfilled, or ends as
rejected or expired. Prizes that need approval
(the default for manually handled prizes) must be approved before they are marked fulfilled.
curl https://api.lucklogic.dev/v1/claims/clm_3t2v... -H "Authorization: Bearer $KEY"
# { "token": "clm_3t2v...", "status": "pending", "redemption": { ... }, "fulfilment": { ... }, ... }
curl -X PATCH https://api.lucklogic.dev/v1/claims/clm_3t2v... -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{ "status": "approved" }'
curl -X PATCH https://api.lucklogic.dev/v1/claims/clm_3t2v... -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-d '{ "status": "fulfilled", "note": "Sent by post" }'
In-store and event prizes are handed over with
POST /v1/claims/{token}/collect, which is what LuckLogic Verify does. Pass a
location_id to record where, if the brand has collection locations. Every
change is recorded in the claim's history.
Campaign lifecycle
A campaign starts as draft. activate makes it
active; pause and
resume switch between active and
paused; complete ends it from either. Each is a
POST /v1/campaigns/{id}/<action>. Redemptions are only accepted while a
campaign is active and inside its window.
A running campaign can still change. POST /v1/campaigns/{id}/reschedule moves
starts_at or ends_at and lays the remaining
winning moments out again over the new window.
PATCH /v1/campaigns/{id}/prize-tiers/{tier} raises or lowers a prize's
quantity and POST /v1/campaigns/{id}/prize-tiers
adds a prize; prizes already won are never taken back. In production each change needs a
reason, the start can only move before the campaign has started, and
GET /v1/campaigns/{id}/changes lists who changed what, when and why.
Errors
Every error has the same shape, and the code is stable, so map it to your own
copy in any language.
{
"error": {
"code": "CODE_ALREADY_REDEEMED",
"message": "This code has already been played.",
"details": { "redeemed_at": "2027-07-14T09:21:04.351Z" }
}
}
| Status | code | When |
|---|---|---|
404 |
CODE_NOT_FOUND |
Unknown code, a typo, or a revoked batch. |
400 |
CODE_ALREADY_REDEEMED |
The code was played before. details.redeemed_at says when. |
403 |
CAMPAIGN_NOT_ACTIVE |
Draft, paused, completed, not started yet, or ended. |
429 |
RATE_LIMIT_EXCEEDED |
The participant reached the campaign's limit. Honour Retry-After. |
400 |
PARTICIPANT_REQUIRED |
The campaign has a limit but the request had no participant_id or IP. |
409 |
IDEMPOTENCY_KEY_REUSED |
The same Idempotency-Key was sent with a different request. |
429 |
API_RATE_LIMIT_EXCEEDED |
Your key is sending requests too fast. |
503 |
RETRY_LATER |
The same code is being processed by another request. Retry shortly. |
400 |
INVALID_STATE |
The action does not fit the current status, e.g. fulfilling a pending claim. |
400 |
VALIDATION_ERROR |
The body or parameters are malformed. details lists each field. |
401 |
UNAUTHORIZED |
Missing, malformed or revoked key. |
Safe retries
Send an Idempotency-Key header, any unique string such as a UUID, with each
redemption. If the network drops and you retry with the same key and body, you get the original response
back, never a second redemption. The same key with a different body is refused with
IDEMPOTENCY_KEY_REUSED. Independently of keys, a code can only ever be
redeemed once, and two simultaneous requests for the last prize produce exactly one winner.
Webhooks
Register an endpoint with POST /v1/webhooks to receive
prize.claimed for every win and claim.updated for
every claim status change. POST /v1/webhooks/{id}/test sends a
webhook.test event.
{
"event": "prize.claimed",
"campaign_id": "camp_f084...",
"timestamp": "2027-07-14T09:21:04.400Z",
"data": {
"redemption_id": "rdm_607c...",
"participant_id": "crm_12345",
"prize_tier": "secondary",
"prize_name": "Festival weekend pass",
"claim_token": "clm_3t2v...",
"redeemed_at": "2027-07-14T09:21:04.351Z"
}
}
Each delivery carries X-LuckLogic-Event,
X-LuckLogic-Delivery and
X-LuckLogic-Signature (t=<unix time>,v1=<hex>). Verify the signature over the raw body before trusting it:
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verify(secret: string, signatureHeader: string, rawBody: string): boolean {
const { t, v1 } = Object.fromEntries(signatureHeader.split(',').map((kv) => kv.split('=')));
if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false; // reject replays
const key = Buffer.from(secret.replace('whsec_', ''), 'base64url');
const expected = createHmac('sha256', key).update(`${t}.${rawBody}`).digest('hex');
return expected.length === v1.length && timingSafeEqual(Buffer.from(expected), Buffer.from(v1));
}
Deliveries that do not get a 2xx within 10 seconds are retried after 1 minute, 5 minutes, 30 minutes, 2
hours and 12 hours. With the Node.js SDK, the check above is
verifyWebhook(). The delivery log,
GET /v1/webhooks/{id}/deliveries, shows each attempt, and a failed delivery
can be replayed.
Sandbox helpers
With a sk_test_ key you can make the next valid code win, or start a campaign
over:
curl -X POST https://api.lucklogic.dev/v1/sandbox/campaigns/camp_f084.../force-win \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d '{ "tier": "main" }'
curl -X POST https://api.lucklogic.dev/v1/sandbox/campaigns/camp_f084.../reset -H "Authorization: Bearer $KEY"
A Next.js route
The API key stays on the server. The browser posts the code to this route, and the route calls LuckLogic. The same pattern works in Express, Laravel, Rails or any other backend.
import { NextResponse } from 'next/server';
import { randomUUID } from 'node:crypto';
export async function POST(req: Request) {
const { code, userId } = await req.json();
const res = await fetch('https://api.lucklogic.dev/v1/redemptions', {
method: 'POST',
headers: {
authorization: `Bearer ${process.env.LUCKLOGIC_SECRET_KEY}`,
'content-type': 'application/json',
'idempotency-key': randomUUID(),
},
body: JSON.stringify({
campaign_id: process.env.LUCKLOGIC_CAMPAIGN_ID,
code,
participant_id: userId,
}),
});
const body = await res.json();
if (!res.ok) return NextResponse.json({ error: body.error.code }, { status: res.status });
return NextResponse.json({ outcome: body.outcome, prize: body.prize, claimToken: body.claim_token });
}
@lucklogic/node
The official client for Node.js 20 and later. Every endpoint is a typed method, generated from the same
OpenAPI document as the API reference, with
the same field names. It retries only what cannot happen twice: each redemption carries an
Idempotency-Key reused across attempts, so a timeout never redeems a code
twice. It has no dependencies.
npm install @lucklogic/node
The Next.js route above, with the SDK:
import { NextResponse } from 'next/server';
import { LuckLogic, isLuckLogicError } from '@lucklogic/node';
const luck = new LuckLogic({ apiKey: process.env.LUCKLOGIC_SECRET_KEY });
export async function POST(req: Request) {
const { code, userId } = await req.json();
try {
const result = await luck.redemptions.create({
campaign_id: process.env.LUCKLOGIC_CAMPAIGN_ID!,
code,
participant_id: userId,
});
return NextResponse.json({ outcome: result.outcome, prize: result.prize, claimToken: result.claim_token });
} catch (err) {
if (isLuckLogicError(err)) return NextResponse.json({ error: err.code }, { status: err.status });
throw err;
}
}
Verifying a webhook returns the typed event, or throws when the signature is wrong or too old:
import { verifyWebhook } from '@lucklogic/node';
export async function POST(req: Request) {
const event = await verifyWebhook({
payload: await req.text(), // the raw body, not parsed JSON
signature: req.headers.get('x-lucklogic-signature'),
secret: process.env.LUCKLOGIC_WEBHOOK_SECRET!,
}).catch(() => null);
if (!event) return new Response('Bad signature', { status: 400 });
if (event.event === 'prize.claimed') {
// event.data.claim_token, event.data.prize_tier, event.data.participant_id
}
return new Response(null, { status: 204 });
}
Campaigns, code batches, claims, webhooks and the sandbox helpers are all there too. The README on npm covers each, and the source is on GitHub.