API reference
Plans
You can now model subscriptions more flexibly using the Prices API. It replaces the Plans API and is backwards compatible to simplify your migration. Plans define the base price, currency, and billing cycle for recurring purchases of products. Products help you track inventory or provisioning, and plans help you track pricing. Different physical goods or levels of service should be represented by products, and pricing options should be represented by plans. This approach lets you change prices without having to change your provisioning scheme. For example, you might have a single "gold" product that has plans for $10/month, $100/year, €9/month, and €90/year. Related guides: Set up a subscription and more about products and prices.
https://api.knoxapi.comCreate a plan
POST/v1/plans
You can now model subscriptions more flexibly using the Prices API. It replaces the Plans API and is backwards compatible to simplify your migration.
Body parameters
currencystringRequiredThree-letter ISO currency code, in lowercase. Must be a supported currency.
intervalstringRequiredSpecifies billing frequency. Either
day,week,monthoryear.Possible valuesdaymonthweekyear
activebooleanWhether the plan is currently available for new subscriptions. Defaults to
true.amountintegerA positive integer in cents (or local equivalent) (or 0 for a free plan) representing how much to charge on a recurring basis.
amount_decimalstringSame as
amount, but accepts a decimal value with at most 12 decimal places. Only one ofamountandamount_decimalcan be set.billing_schemestringDescribes how to compute the price per period. Either
per_unitortiered.per_unitindicates that the fixed amount (specified inamount) will be charged per unit inquantity(for plans withusage_type=licensed), or per unit of total usage (for plans withusage_type=metered).tieredindicates that the unit pricing will be computed using a tiering strategy as defined using thetiersandtiers_modeattributes.Possible valuesper_unittiered
expandarray of stringsSpecifies which fields in the response should be expanded.
idstringAn identifier randomly generated by Stripe. Used to identify this plan when subscribing a customer. You can optionally override this ID, but the ID must be unique across all plans in your Stripe account. You can, however, use the same plan ID in both live and test modes.
interval_countintegerThe number of intervals between subscription billings. For example,
interval=monthandinterval_count=3bills every 3 months. Maximum of three years interval allowed (3 years, 36 months, or 156 weeks).metadataobjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to
metadata.meterstringThe meter tracking the usage of a metered price
nicknamestringA brief description of the plan, hidden from customers.
productobject | stringShow 7 child parameters
namestringRequiredactivebooleanidstringmetadataobjectstatement_descriptorstringtax_codestringunit_labelstring
tiersarray of objectsEach element represents a pricing tier. This parameter requires
billing_schemeto be set totiered. See also the documentation forbilling_scheme.Show 5 child parameters
up_tostring | integerRequiredPossible valuesinf
flat_amountintegerflat_amount_decimalstringunit_amountintegerunit_amount_decimalstring
tiers_modestringDefines if the tiering price should be
graduatedorvolumebased. Involume-based tiering, the maximum quantity within a period determines the per unit price, ingraduatedtiering pricing can successively change as the quantity grows.Possible valuesgraduatedvolume
transform_usageobjectApply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with
tiers.Show 2 child parameters
divide_byintegerRequiredroundstringRequiredPossible valuesdownup
trial_period_daysintegerDefault number of trial days when subscribing a customer to this plan using
trial_from_plan=true.usage_typestringConfigures how the quantity per period should be determined. Can be either
meteredorlicensed.licensedautomatically bills thequantityset when adding it to a subscription.meteredaggregates the total usage based on usage records. Defaults tolicensed.Possible valueslicensedmetered
Returns
The plan object.
curl https://api.knoxapi.com/v1/plans \
-H "Authorization: Bearer $KNOX_SECRET_KEY" \
-d currency=usd \
-d interval=monthconst Stripe = require('stripe');
const stripe = new Stripe(process.env.KNOX_SECRET_KEY, {host: 'api.knoxapi.com'});
const plan = await stripe.plans.create({
currency: 'usd',
interval: 'month',
});import os
import stripe
client = stripe.StripeClient(
os.environ["KNOX_SECRET_KEY"],
base_addresses={"api": "https://api.knoxapi.com"},
)
plan = client.v1.plans.create(params={
"currency": "usd",
"interval": "month",
})require 'stripe'
Stripe.api_key = ENV['KNOX_SECRET_KEY']
Stripe.api_base = 'https://api.knoxapi.com'
plan = Stripe::Plan.create({
currency: 'usd',
interval: 'month',
}){
"active": true,
"amount": 2000,
"amount_decimal": "2000",
"billing_scheme": "per_unit",
"created": 1234567890,
"currency": "usd",
"id": "price_1PgafmB7WZ01zgkW6dKueIc5",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": null,
"object": "plan",
"product": "prod_QXg1hqf4jFNsqG",
"tiers_mode": null,
"transform_usage": {
"divide_by": 1592560163,
"round": "down"
},
"trial_period_days": null,
"usage_type": "licensed"
}List all plans
GET/v1/plans
Returns a list of your plans.
Query parameters
activebooleanOnly return plans that are active or inactive (e.g., pass
falseto list all inactive plans).createdobject | integerA filter on the list, based on the object
createdfield. The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options.Show 4 child parameters
gtintegergteintegerltintegerlteinteger
ending_beforestringA cursor for use in pagination.
ending_beforeis an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting withobj_bar, your subsequent call can includeending_before=obj_barin order to fetch the previous page of the list.expandarray of stringsSpecifies which fields in the response should be expanded.
limitintegerA limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
productstringOnly return plans for the given product.
starting_afterstringA cursor for use in pagination.
starting_afteris an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending withobj_foo, your subsequent call can includestarting_after=obj_fooin order to fetch the next page of the list.
Returns
A list of plan objects.
curl -G https://api.knoxapi.com/v1/plans \
-H "Authorization: Bearer $KNOX_SECRET_KEY" \
--data-urlencode limit=3const Stripe = require('stripe');
const stripe = new Stripe(process.env.KNOX_SECRET_KEY, {host: 'api.knoxapi.com'});
const page = await stripe.plans.list({
limit: 3,
});import os
import stripe
client = stripe.StripeClient(
os.environ["KNOX_SECRET_KEY"],
base_addresses={"api": "https://api.knoxapi.com"},
)
page = client.v1.plans.list(params={
"limit": 3,
})require 'stripe'
Stripe.api_key = ENV['KNOX_SECRET_KEY']
Stripe.api_base = 'https://api.knoxapi.com'
page = Stripe::Plan.list({
limit: 3,
}){
"object": "list",
"url": "/v1/plans",
"has_more": false,
"data": [
{
"active": true,
"amount": 2000,
"amount_decimal": "2000",
"billing_scheme": "per_unit",
"created": 1234567890,
"currency": "usd",
"id": "price_1PgafmB7WZ01zgkW6dKueIc5",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": null,
"object": "plan",
"product": "prod_QXg1hqf4jFNsqG",
"tiers_mode": null,
"transform_usage": {
"divide_by": 1592560163,
"round": "down"
},
"trial_period_days": null,
"usage_type": "licensed"
}
]
}Update a plan
POST/v1/plans/{plan}
Updates the specified plan by setting the values of the parameters passed. Any parameters not provided are left unchanged. By design, you cannot change a plan’s ID, amount, currency, or billing cycle.
Path parameters
planstringRequired
Body parameters
activebooleanWhether the plan is currently available for new subscriptions.
expandarray of stringsSpecifies which fields in the response should be expanded.
metadataobjectSet of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to
metadata.nicknamestringA brief description of the plan, hidden from customers.
productstringThe product the plan belongs to. This cannot be changed once it has been used in a subscription or subscription schedule.
trial_period_daysintegerDefault number of trial days when subscribing a customer to this plan using
trial_from_plan=true.
Returns
The plan object.
curl https://api.knoxapi.com/v1/plans/price_1PgafmB7WZ01zgkW6dKueIc5 \
-H "Authorization: Bearer $KNOX_SECRET_KEY" \
-d "metadata[order_id]=6735"const Stripe = require('stripe');
const stripe = new Stripe(process.env.KNOX_SECRET_KEY, {host: 'api.knoxapi.com'});
const plan = await stripe.plans.update('price_1PgafmB7WZ01zgkW6dKueIc5', {
metadata: {
order_id: '6735',
},
});import os
import stripe
client = stripe.StripeClient(
os.environ["KNOX_SECRET_KEY"],
base_addresses={"api": "https://api.knoxapi.com"},
)
plan = client.v1.plans.update("price_1PgafmB7WZ01zgkW6dKueIc5", params={
"metadata": {
"order_id": "6735",
},
})require 'stripe'
Stripe.api_key = ENV['KNOX_SECRET_KEY']
Stripe.api_base = 'https://api.knoxapi.com'
plan = Stripe::Plan.update('price_1PgafmB7WZ01zgkW6dKueIc5', {
metadata: {
order_id: '6735',
},
}){
"active": true,
"amount": 2000,
"amount_decimal": "2000",
"billing_scheme": "per_unit",
"created": 1234567890,
"currency": "usd",
"id": "price_1PgafmB7WZ01zgkW6dKueIc5",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": null,
"object": "plan",
"product": "prod_QXg1hqf4jFNsqG",
"tiers_mode": null,
"transform_usage": {
"divide_by": 1592560163,
"round": "down"
},
"trial_period_days": null,
"usage_type": "licensed"
}Retrieve a plan
GET/v1/plans/{plan}
Retrieves the plan with the given ID.
Path parameters
planstringRequired
Query parameters
expandarray of stringsSpecifies which fields in the response should be expanded.
Returns
The plan object.
curl https://api.knoxapi.com/v1/plans/price_1PgafmB7WZ01zgkW6dKueIc5 \
-H "Authorization: Bearer $KNOX_SECRET_KEY"const Stripe = require('stripe');
const stripe = new Stripe(process.env.KNOX_SECRET_KEY, {host: 'api.knoxapi.com'});
const plan = await stripe.plans.retrieve('price_1PgafmB7WZ01zgkW6dKueIc5');import os
import stripe
client = stripe.StripeClient(
os.environ["KNOX_SECRET_KEY"],
base_addresses={"api": "https://api.knoxapi.com"},
)
plan = client.v1.plans.retrieve("price_1PgafmB7WZ01zgkW6dKueIc5")require 'stripe'
Stripe.api_key = ENV['KNOX_SECRET_KEY']
Stripe.api_base = 'https://api.knoxapi.com'
plan = Stripe::Plan.retrieve('price_1PgafmB7WZ01zgkW6dKueIc5'){
"active": true,
"amount": 2000,
"amount_decimal": "2000",
"billing_scheme": "per_unit",
"created": 1234567890,
"currency": "usd",
"id": "price_1PgafmB7WZ01zgkW6dKueIc5",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"meter": null,
"nickname": null,
"object": "plan",
"product": "prod_QXg1hqf4jFNsqG",
"tiers_mode": null,
"transform_usage": {
"divide_by": 1592560163,
"round": "down"
},
"trial_period_days": null,
"usage_type": "licensed"
}Delete a plan
DELETE/v1/plans/{plan}
Deleting plans means new subscribers can’t be added. Existing subscribers aren’t affected.
Path parameters
planstringRequired
Returns
The deleted_plan object.
curl -X DELETE https://api.knoxapi.com/v1/plans/price_1PgafmB7WZ01zgkW6dKueIc5 \
-H "Authorization: Bearer $KNOX_SECRET_KEY"const Stripe = require('stripe');
const stripe = new Stripe(process.env.KNOX_SECRET_KEY, {host: 'api.knoxapi.com'});
const deletedPlan = await stripe.plans.del('price_1PgafmB7WZ01zgkW6dKueIc5');import os
import stripe
client = stripe.StripeClient(
os.environ["KNOX_SECRET_KEY"],
base_addresses={"api": "https://api.knoxapi.com"},
)
deleted_plan = client.v1.plans.delete("price_1PgafmB7WZ01zgkW6dKueIc5")require 'stripe'
Stripe.api_key = ENV['KNOX_SECRET_KEY']
Stripe.api_base = 'https://api.knoxapi.com'
deleted_plan = Stripe::Plan.delete('price_1PgafmB7WZ01zgkW6dKueIc5'){
"deleted": true,
"id": "price_1PgafmB7WZ01zgkW6dKueIc5",
"object": "plan"
}Operations and schemas come from the pinned Stripe OpenAPI specification (MIT); response examples from its fixtures. Nested object definitions and enums are in the complete specification.