Issue coupon codes — one code or a batch
Create the coupon with its terms, mint a batch of unique single-use codes that unlock it, and export the codes with their redemption status for the campaign.
Promotions & loyalty · a play in 3 steps.
The steps
- Create the coupon — the terms a presented code unlocks. — createCoupon
- Mint a batch of unique single-use codes for the coupon — up to 48 per call. — createCouponBatch
- Export the batch’s codes with their redemption status. — couponBatchCodes
The calls
Every operation this use case runs, in the order it first appears, with the request and the response its reference page shows.
createCoupon
createCoupon — mutation · Create a new coupon — a code a customer presents for a reduction at your organization.
Example request
mutation ExampleCreateCoupon($input: NewCouponInput!) {
createCoupon(input: $input) {
id
sysId
type
caption
status
parentId
rootId
createdAt
updatedAt
revisionNum
revision
flavor
code
promotionId
startAt
endAt
totalUsesCap
}
}
Variables:
{
"input": {
"caption": "Blue jeans",
"code": "BJ-001",
"flavor": "trigger"
}
}
Send it with the envelope naming the version: "extensions": {"at": {"version": {"name":"genesis","number":0}}}.
Example response
{
"data": {
"createCoupon": {
"id": "01900000-0000-7000-8000-37386ae00000",
"sysId": "CP-EXMP-0000-000F",
"type": "Coupon",
"caption": "Blue jeans",
"status": "active",
"parentId": "01900000-0000-7000-8000-065235280000",
"rootId": "01900000-0000-7000-8000-a093dd800000",
"createdAt": "2027-01-31T00:00:00.000Z",
"updatedAt": "2027-01-31T00:00:00.000Z",
"revisionNum": 1,
"revision": "01900000-0000-7000-8000-b7960e180000",
"flavor": "trigger",
"code": "BJ-001",
"promotionId": "01900000-0000-7000-8000-59bbd0c70000",
"startAt": "2027-01-31T00:00:00.000Z",
"endAt": "2027-01-31T00:00:00.000Z",
"totalUsesCap": 1
}
},
"extensions": {
"at": {
"callId": "01EXAMPLE-CALL-ID",
"version": {
"requested": {
"name": "genesis",
"number": 0
},
"serviced": {
"name": "genesis",
"number": 0
}
}
}
}
}
createCouponBatch
createCouponBatch — mutation · Mint a batch of unique single-use codes (up to 48) that all unlock one existing coupon’s terms.
Example request
mutation ExampleCreateCouponBatch($couponId: ID!, $count: Int!, $codePrefix: String!, $caption: String) {
createCouponBatch(couponId: $couponId, count: $count, codePrefix: $codePrefix, caption: $caption) {
couponBatch {
id
sysId
type
caption
status
parentId
rootId
createdAt
updatedAt
revisionNum
revision
codePrefix
codeCount
}
}
}
Variables:
{
"couponId": "01900000-0000-7000-8000-d21413c60000",
"count": 1,
"codePrefix": "<code prefix>",
"caption": "Blue jeans"
}
Send it with the envelope naming the version: "extensions": {"at": {"version": {"name":"genesis","number":0}}}.
Example response
{
"data": {
"createCouponBatch": {
"couponBatch": {
"id": "01900000-0000-7000-8000-37386ae00000",
"sysId": "CB-EXMP-0000-000F",
"type": "CouponBatch",
"caption": "Blue jeans",
"status": "active",
"parentId": "01900000-0000-7000-8000-065235280000",
"rootId": "01900000-0000-7000-8000-a093dd800000",
"createdAt": "2027-01-31T00:00:00.000Z",
"updatedAt": "2027-01-31T00:00:00.000Z",
"revisionNum": 1,
"revision": "01900000-0000-7000-8000-b7960e180000",
"codePrefix": "<code prefix>",
"codeCount": 1
}
}
},
"extensions": {
"at": {
"callId": "01EXAMPLE-CALL-ID",
"version": {
"requested": {
"name": "genesis",
"number": 0
},
"serviced": {
"name": "genesis",
"number": 0
}
}
}
}
}
couponBatchCodes
couponBatchCodes — query · One batch’s unique codes with their redemption status — the list you export for a campaign.
Example request
query ExampleCouponBatchCodes($batchId: ID!, $limit: Int) {
couponBatchCodes(batchId: $batchId, limit: $limit) {
items {
id
code
status
redeemedAt
orderId
}
nextToken
}
}
Variables:
{
"batchId": "01900000-0000-7000-8000-cb95c0160000",
"limit": 1
}
Example response
{
"data": {
"couponBatchCodes": {
"items": [
{
"id": "01900000-0000-7000-8000-37386ae00000",
"code": "BJ-001",
"status": "<status>",
"redeemedAt": "2027-01-31T00:00:00.000Z",
"orderId": "01900000-0000-7000-8000-f6d8263a0000"
}
],
"nextToken": "<the cursor from the previous page>"
}
},
"extensions": {
"at": {
"callId": "01EXAMPLE-CALL-ID",
"version": {
"requested": null,
"serviced": {
"name": "genesis",
"number": 0
}
}
}
}
}