Skip to content

Generate Codes

POST /v1/campaigns/codes/generate

Generates a batch of unique, redeemable codes for the campaign. Each code awards a fixed number of points when redeemed. Codes are returned in plaintext only once — store them securely.

HeaderRequiredValue
X-API-SecretYesYour secret key
Content-TypeYesapplication/json
FieldTypeRequiredDescription
slugstringYesCampaign slug (e.g., summer-promo)
batchSizeintegerYesNumber of codes to generate (1—10,000)
pointsValueintegerYesPoints each code awards when redeemed
labelstringNoLabel for this batch (e.g., “Holiday campaign mailers”)
expiresAtdatetimeNoISO 8601 expiration date for the codes
Terminal window
curl -X POST https://api.gamifyhost.com/v1/campaigns/codes/generate \
-H "X-API-Secret: sk_live_your_secret_key" \
-H "Content-Type: application/json" \
-d '{
"slug": "summer-promo",
"batchSize": 100,
"pointsValue": 500,
"label": "In-store promo cards",
"expiresAt": "2025-12-31T23:59:59Z"
}'

Status: 200 OK

{
"status": "success",
"data": {
"batch": {
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"campaignId": "c1d2e3f4-a5b6-7890-1234-567890abcdef",
"batchSize": 100,
"pointsValue": 500,
"label": "In-store promo cards",
"expiresAt": "2025-12-31T23:59:59Z",
"createdAt": "2025-07-15T10:00:00Z"
},
"codes": [
"SUMM-AX7K9M2P",
"SUMM-BF3D8N4Q",
"SUMM-CG5H2R6T",
"..."
],
"count": 100,
"gameUrl": "https://app.gamifyhost.com/campaign/summer-promo"
}
}

Codes follow the pattern PREFIX-XXXXXXXX where:

  • PREFIX — First 4 characters of the campaign slug (uppercased)
  • XXXXXXXX — 8 random characters from a reduced charset (no confusing characters like O/0/I/1/L)
FieldTypeDescription
batchobjectBatch metadata
batch.iduuidUnique batch ID
batch.batchSizeintegerNumber of codes generated
batch.pointsValueintegerPoints per code
batch.labelstringBatch label
codesstring[]Array of plaintext codes
countintegerNumber of codes generated
gameUrlstringPublic campaign page URL
  • In-store promotions: Print codes on receipts, packaging, or promotional cards
  • Email campaigns: Include unique codes in marketing emails
  • Partner distributions: Share codes with influencers or affiliate partners
  • Event giveaways: Hand out codes at physical events or trade shows
CodeMessage
400batchSize must be between 1 and 10000
400pointsValue must be positive
404Campaign not found