Skip to content

Coupons Query

Note: The Teachify Admin API is currently under development and not yet available for public use. This documentation is provided for preview purposes only.

The Coupon API allows you to retrieve information about discount coupons in your school. Coupons enable you to offer promotional discounts on your courses, events, and other products. This API provides access to coupon details, usage statistics, and filtering capabilities.

Returns a paginated list of coupons for the authenticated school.

Parameters:

ParameterTypeDescription
filterAdminCouponFilterFilter criteria (see Filtering)
pageIntPage number for pagination
perPageIntNumber of items per page (default: 20, max: 50)
limitIntAlternative to perPage

Returns:

  • AdminCouponPage object with:
    • nodes: Array of AdminCoupon objects
    • currentPage: Current page number
    • hasNextPage: Whether there are more pages
    • hasPreviousPage: Whether there are previous pages
    • nodesCount: Total number of items across all pages
    • totalPages: Total number of pages

Example:

query {
coupons(
filter: {
active: true,
code: { like: "SUMMER%" }
},
page: 1,
perPage: 10
) {
nodes {
id
name
code
amount
couponType
active
appliedCount
expiredAt
}
currentPage
hasNextPage
hasPreviousPage
nodesCount
totalPages
}
}

Returns one coupon’s member grants, paginated, newest grantedAt first. Requires the coupons:read and students:read scopes (members:read is accepted in place of students:read), since each grant carries the member’s name and email.

Parameters:

ParameterTypeDescription
couponIdString!ID of the coupon. A coupon that is not in your school, or is deleted, returns an empty page
status[AdminCouponGrantStatus!]Only grants in these statuses: granted, redeemed, revoked, expired. Omit to return every status; an empty list returns none
filterAdminCouponGrantFilteruserId or userEmail (StringOperator). userEmail is matched case-insensitively. For userId use eq or in; like and contains are ignored on IDs
pageIntPage number for pagination
perPageIntNumber of items per page (default: 20, max: 50)
limitIntAlternative to perPage

Returns: an AdminCouponGrantPage with the same pagination fields as coupons; nodes holds AdminCouponGrant objects.

Example: find a member’s grant so it can be revoked with revokeCouponGrant. Any grant whose revokedAt is null can be revoked, including a redeemed one or one whose coupon has expired:

query {
couponGrants(
couponId: "4f0c2a9e-7b1d-4c3e-9a52-8d6e1f3b7c20",
filter: { userEmail: { eq: "member@example.com" } }
) {
nodes {
id
status
userEmail
grantedAt
revokedAt
}
nodesCount
}
}

The AdminCoupon object contains the following fields based on the schema:

FieldTypeDescription
idString!Unique identifier
nameString!Name of the coupon
codeString!Unique coupon code that users enter to apply the discount
descriptionStringOptional description of the coupon
amountFloat!Discount amount (in currency units or percentage based on couponType)
couponTypeString!Type of discount: “fixed_amount” or “percentage”
currencyString!Currency code (e.g., USD, EUR) in ISO 4217 format
currencySymbolString!Currency symbol (e.g., $, €, £, ¥)
activeBoolean!Whether the coupon is currently active
restrictedBoolean!Whether the coupon is grant-only: only members holding a grant for it can redeem it. Only a restricted coupon can be granted with createCouponGrant
oncePerUserBoolean!Whether each member may redeem the coupon only once
singleProductBoolean!Whether coupon applies to a single product only
appliedCountInt!Number of times the coupon has been used
redemptionLimitIntMaximum number of times the coupon can be used (null for unlimited). Not enforced for restricted coupons
startedAtIntWhen the coupon becomes valid
expiredAtIntWhen the coupon expires
stateString!Lifecycle state: scheduled, activated or expired. Coupons created through the API or the school admin stay scheduled, so do not use it to tell whether a coupon can be redeemed; use active, startedAt and expiredAt
items[JSON!]Related products the coupon can be applied to
applicableItems[AdminCouponApplicableItem!]!Labelled products the coupon applies to. A course or event lists its plans or tickets as children. Empty when the coupon applies to every product
grants[AdminCouponGrant!]!All grants of the coupon in one unpaginated list, revoked ones included, ordered by grantedAt descending. Requires students:read or members:read, as couponGrants does. Use couponGrants to page through them or find one member’s grant. See AdminCouponGrant
createdAtInt!When the coupon was created
updatedAtInt!When the coupon was last updated

The coupons query supports filtering through the filter parameter. The following filter fields are available:

Filter FieldTypeDescription
idStringOperatorFilter by coupon ID
codeStringOperatorFilter by coupon code
nameStringOperatorFilter by coupon name
couponTypeStringOperatorFilter by coupon type (fixed_amount, percentage)
stateStringOperatorFilter by coupon state (scheduled, activated, expired). See the state field above
activeBooleanFilter for active/inactive coupons
singleProductBooleanFilter for single product coupons

String fields can be filtered using the following operators:

OperatorDescriptionExample
eqEqual to{ code: { eq: "SUMMER2023" } }
neqNot equal to{ code: { neq: "SUMMER2023" } }
inIn a list of values{ code: { in: ["SUMMER2023", "FALL2023"] } }
ninNot in a list of values{ code: { nin: ["EXPIRED2022"] } }
likePattern matching (case-sensitive){ code: { like: "SUMMER%" } }

Find active percentage-based coupons:

query {
coupons(
filter: {
active: true,
couponType: { eq: "percentage" }
}
) {
nodes {
id
name
code
amount
appliedCount
}
}
}

Find coupons by name pattern:

query {
coupons(
filter: {
name: { like: "Summer%" }
}
) {
nodes {
id
name
code
amount
couponType
}
}
}

The Coupon API indirectly relates to:

  • Products: Coupons can be applied to one or more products (courses, events, etc.)
  • Payments: Payments track the application of coupons as adjustments
  • Users: Users apply coupons during checkout

Below is a comprehensive view of fields available in the coupons query based on the schema:

query {
coupons(
filter: {
id: { eq: "4f0c2a9e-7b1d-4c3e-9a52-8d6e1f3b7c20" } # Filter by ID (StringOperator)
code: { like: "WELCOME%" } # Filter by code pattern (StringOperator)
name: { like: "Welcome%" } # Filter by name pattern (StringOperator)
couponType: { eq: "percentage" } # Filter by coupon type (StringOperator)
state: { eq: "scheduled" } # Filter by state (StringOperator)
active: true # Filter for active coupons (Boolean)
singleProduct: false # Filter for multi-product coupons (Boolean)
},
page: 1, # Page number (Int)
perPage: 20 # Items per page (Int)
) {
nodes {
id # Unique identifier (String!)
name # Coupon name (String!)
code # Coupon code (String!)
description # Optional description (String)
# Discount information
amount # Discount amount (Float!)
couponType # Type of discount: fixed_amount or percentage (String!)
currency # Currency code (String!)
currencySymbol # Currency symbol (String!)
# Status fields
active # Whether the coupon is active (Boolean!)
restricted # Grant-only coupon (Boolean!)
oncePerUser # Each member may redeem it only once (Boolean!)
singleProduct # Whether coupon applies to single product only (Boolean!)
# Usage statistics
appliedCount # Number of times used (Int!)
redemptionLimit # Maximum usage limit (Int)
# Time-related fields
startedAt # When the coupon becomes valid (Int)
expiredAt # When the coupon expires (Int)
state # Lifecycle state (String!)
createdAt # Creation timestamp (Int!)
updatedAt # Last update timestamp (Int!)
# Related items
items # Products the coupon can be applied to ([JSON!])
applicableItems { # Labelled products, empty when it applies to everything
id
label
type
amount
children { id label type amount } # Plans of a course, tickets of an event
}
# Grants (restricted coupons)
grants { # Every grant, revoked ones included
id
status
userEmail
grantedAt
redeemedAt
revokedAt
}
}
# Pagination information
currentPage # Current page number (Int!)
hasNextPage # Whether there are more pages (Boolean!)
hasPreviousPage # Whether there are previous pages (Boolean!)
nodesCount # Total number of items across all pages (Int!)
totalPages # Total number of pages (Int!)
}
}
  • Coupon Mutations — create and update coupons, and grant or revoke grant-only (restricted) coupons for members