AlmondTill/G3N API

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.

In the office

Where it starts: the office’s Coupons page.

Step 1. Create the coupon — the terms a presented code unlocks. Open Coupons.

Step 2. Mint a batch of unique single-use codes for the coupon — up to 48 per call. Open Coupon batches.

Step 3. Export the batch’s codes with their redemption status.

For developers — the calls

The steps

  1. Create the coupon — the terms a presented code unlocks. — createCoupon
  2. Mint a batch of unique single-use codes for the coupon — up to 48 per call. — createCouponBatch
  3. 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

graphql
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:

json
{
  "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

json
{
  "data": {
    "createCoupon": {
      "id": "01900000-0000-7000-8000-d554478b0000",
      "sysId": "CP-EXMP-0000-000F",
      "type": "Coupon",
      "caption": "Blue jeans",
      "status": "active",
      "parentId": "01900000-0000-7000-8000-eacdfcfd0000",
      "rootId": "01900000-0000-7000-8000-a1295a650000",
      "createdAt": "2027-01-31T00:00:00.000Z",
      "updatedAt": "2027-01-31T00:00:00.000Z",
      "revisionNum": 0,
      "revision": "01900000-0000-7000-8000-53c6eea90000",
      "flavor": "trigger",
      "code": "BJ-001",
      "promotionId": "01900000-0000-7000-8000-3b80190a0000",
      "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

graphql
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:

json
{
  "couponId": "01900000-0000-7000-8000-d554478b0000",
  "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

json
{
  "data": {
    "createCouponBatch": {
      "couponBatch": {
        "id": "01900000-0000-7000-8000-fc56cc5d0000",
        "sysId": "CB-EXMP-0000-000F",
        "type": "CouponBatch",
        "caption": "Blue jeans",
        "status": "active",
        "parentId": "01900000-0000-7000-8000-d554478b0000",
        "rootId": "01900000-0000-7000-8000-a1295a650000",
        "createdAt": "2027-01-31T00:00:00.000Z",
        "updatedAt": "2027-01-31T00:00:00.000Z",
        "revisionNum": 0,
        "revision": "01900000-0000-7000-8000-53c6eea90000",
        "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

graphql
query ExampleCouponBatchCodes($batchId: ID!, $limit: Int) {
  couponBatchCodes(batchId: $batchId, limit: $limit) {
    items {
      id
      code
      status
      redeemedAt
      orderId
    }
    nextToken
  }
}

Variables:

json
{
  "batchId": "01900000-0000-7000-8000-ebfe629b0000",
  "limit": 1
}

Example response

json
{
  "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-18e782370000"
        }
      ],
      "nextToken": "<the cursor from the previous page>"
    }
  },
  "extensions": {
    "at": {
      "callId": "01EXAMPLE-CALL-ID",
      "version": {
        "requested": null,
        "serviced": {
          "name": "genesis",
          "number": 0
        }
      }
    }
  }
}