Create Coupon Code API

Create promotional coupon codes with customizable discounts and usage limits

Promotions

Create Coupon Code API

Generate promotional coupon codes for discounts and special offers. Configure discount amounts, validity periods, and usage restrictions.

Custom Codes

Create custom or auto-generated codes.

Flexible Discounts

Percentage or fixed amount discounts.

Time Limits

Set validity periods for promotions.


Endpoint Overview

MUTATION/graphql

Create a new promotional coupon code with configurable discount type, value, usage limits, and validity period.

Authentication:Bearer Token
Required scopes:admin

Request Parameters

codeString!Required

The coupon code string (or auto-generate if not provided).

discountTypeString!Required

Type of discount: "PERCENTAGE" or "FIXED_AMOUNT".

discountValueFloat!Required

Discount amount (percentage 0-100 or fixed amount).

maxUsesInt

Maximum total number of times the code can be used.

maxUsesPerUserInt

Maximum uses per individual user.

validFromDateTime

Start date for coupon validity.

validUntilDateTime

End date for coupon validity.

applicablePlans[Int]

List of plan IDs this coupon applies to.

minPurchaseAmountFloat

Minimum purchase amount required.


GraphQL Mutation

mutation createCouponCode($coupon: CouponCodeInput!) {
  createCouponCode(coupon: $coupon) {
    id
    code
    discountType
    discountValue
    maxUses
    usedCount
    validFrom
    validUntil
    active
  }
}

Variables:

{
  "coupon": {
    "code": "SUMMER2024",
    "discountType": "PERCENTAGE",
    "discountValue": 25,
    "maxUses": 1000,
    "maxUsesPerUser": 1,
    "validFrom": "2024-06-01T00:00:00Z",
    "validUntil": "2024-08-31T23:59:59Z"
  }
}

HTTP Request:

curl -X POST https://api.orbnet.com/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -d '{
    "query": "mutation createCouponCode($coupon: CouponCodeInput!) { createCouponCode(coupon: $coupon) { id code discountType discountValue } }",
    "variables": {
      "coupon": {
        "code": "SUMMER2024",
        "discountType": "PERCENTAGE",
        "discountValue": 25
      }
    }
  }'

Response

200Coupon Created Successfully
{
  "data": {
    "createCouponCode": {
      "id": "coupon_123",
      "code": "SUMMER2024",
      "discountType": "PERCENTAGE",
      "discountValue": 25,
      "maxUses": 1000,
      "usedCount": 0,
      "validFrom": "2024-06-01T00:00:00Z",
      "validUntil": "2024-08-31T23:59:59Z",
      "active": true
    }
  }
}
400Code Already Exists
{
  "errors": [
    {
      "message": "Coupon code already exists",
      "path": ["createCouponCode"],
      "extensions": {
        "code": "DUPLICATE_CODE"
      }
    }
  ],
  "data": null
}

Coupon Types

Percentage Off

25% off, 50% off - applies to total price.

Fixed Amount

$10 off, $25 off - fixed discount.

First Purchase

One-time use for new customers.

Seasonal

Time-limited promotional codes.


Best Practices

Clear Naming

Use memorable, descriptive code names.

Set Limits

Always set usage and time limits.

Track Performance

Monitor redemption rates and revenue impact.

Plan Restrictions

Consider limiting to specific plans.



Testing Coupons

Create test coupons with very limited uses to verify functionality before launching promotions.

Validate Coupons

Use the Check Coupon Code API to validate coupons before applying them to purchases.

Check Coupon Code