Use Coupon Code API

Apply a validated coupon code to a purchase for discounts

Apply Discount

Use Coupon Code API

Apply coupon codes to purchases and receive discounts. Automatically calculates and applies the discount to the transaction.

Apply Discount

Instantly apply coupon to purchase.

Auto Calculate

Discount calculated automatically.

Usage Tracking

Tracks redemption and limits.


Endpoint Overview

MUTATION/graphql

Apply a coupon code to a purchase. The discount is calculated and applied, and the coupon usage is recorded.

Authentication:Bearer Token

Request Parameters

codeString!Required

The coupon code to apply.

purchaseIdInt!Required

The ID of the purchase or cart to apply the coupon to.


GraphQL Mutation

mutation useCouponCode($code: String!, $purchaseId: Int!) {
  useCouponCode(code: $code, purchaseId: $purchaseId) {
    success
    discountApplied
    originalPrice
    finalPrice
    message
  }
}

Variables:

{
  "code": "SUMMER2024",
  "purchaseId": 12345
}

HTTP Request:

curl -X POST https://api.orbnet.com/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{
    "query": "mutation useCouponCode($code: String!, $purchaseId: Int!) { useCouponCode(code: $code, purchaseId: $purchaseId) { success discountApplied finalPrice message } }",
    "variables": {
      "code": "SUMMER2024",
      "purchaseId": 12345
    }
  }'

Response

200Coupon Applied Successfully
{
  "data": {
    "useCouponCode": {
      "success": true,
      "discountApplied": 24.99,
      "originalPrice": 99.99,
      "finalPrice": 75.00,
      "message": "25% discount applied successfully"
    }
  }
}
400Coupon Already Used
{
  "errors": [
    {
      "message": "You have already used this coupon",
      "path": ["useCouponCode"],
      "extensions": {
        "code": "COUPON_ALREADY_USED"
      }
    }
  ],
  "data": null
}
400Coupon Expired
{
  "errors": [
    {
      "message": "Coupon has expired",
      "path": ["useCouponCode"],
      "extensions": {
        "code": "COUPON_EXPIRED"
      }
    }
  ],
  "data": null
}

Application Flow

Validate First

Apply Coupon

Discount Applied

Complete Purchase


Error Handling

Invalid Code

Code doesn't exist or is misspelled.

Expired

Coupon validity period has ended.

Usage Limit

Maximum uses reached for this code.

Already Used

User has already redeemed this code.


Best Practices

Validate First

Always validate coupons before applying.

Handle Errors

Show clear error messages to users.

Confirm Price

Display final price after discount.

One per Purchase

Typically allow only one coupon per purchase.



Validate First

Always use the Check Coupon Code API before applying to provide better user experience and prevent errors.

Create New Promotions

Need new coupon codes? Create promotional coupons for your marketing campaigns.

Create Coupon Code