Skip to content

Cancel Subscription

The cancelSubscription mutation allows you to programmatically cancel an active subscription for a user. This enables you to revoke access to premium content or membership benefits at the end of the current billing period or immediately.

Input Parameters

FieldTypeDescription
idString!ID of the subscription to cancel
cancelAtPeriodEndBooleanIf true, cancels at period end; if false, cancels immediately or at specified time (default: true)
customEndedAtIntSpecific time to end the subscription (Unix Timestamp). Overrides the default behavior

Return Type

type CancelSubscriptionPayload {
# Array of error messages, if any occurred during the operation
errors: [String!]!
# The cancelled subscription object, null if operation failed
subscription: Subscription
}

Subscription Object

type Subscription {
id: String!
# Unix Timestamp. The date when the subscription was cancelled. Null if not cancelled.
canceledAt: Int
# Unix Timestamp. The end date of the current billing period. For active subscriptions, this represents when the next payment will be due.
currentPeriodEnd: BigInt
# Unix Timestamp. The start date of the current billing period.
currentPeriodStart: BigInt
# Unix Timestamp. The date when the subscription ends. For cancelled subscriptions, this represents the final termination date.
endAt: BigInt
# Indicates whether this subscription will be cancelled in the next billing cycle
isCanceling: Boolean!
# Indicates whether this subscription can be cancelled
isCancellable: Boolean!
# Timestamp of the next scheduled charge. Null for non-recurring or inactive subscriptions.
nextChargeDate: BigInt
payments: [Payment!]
plan: MembershipPlan!
planId: String!
# Unix Timestamp. The date when the subscription starts.
startAt: BigInt
# Possible values: active, incomplete, incomplete_expired, trialing, past_due, canceled, expired
state: String!
# The user who owns this subscription
user: User!
}

Example

mutation CancelSubscription {
cancelSubscription(
id: "sub_12345"
) {
subscription {
planId
startAt
id
user {
name
email
id
}
}
}
}

Sample Response

{
"data": {
"cancelSubscription": {
"errors": [],
"subscription": {
"planId": "sub_id_12345",
"startAt": "1745561281",
"id": "1af2d4fc-1bfb-4e03-a11d-6254bf175adb",
"user": {
"name": "student",
"email": "[email protected]",
"id": "abaed4c4-4d48-4118-a3e8-34d89d540335"
}
}
}
}
}

Common Errors

ErrorDescription
Subscription already cancelledThe subscription is already in a cancelled state

For more information about the Teachify Admin API, please refer to the API Overview.