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.

Knox answers these operations with the same requests and responses as Stripe's API. Authenticate with your secret key, Authorization: Bearer sk_test_..., from your server, and send form-encoded bodies. Test mode only: live processing is currently disabled.

Create 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

  • currencystringRequired

    Three-letter ISO currency code, in lowercase. Must be a supported currency.

  • intervalstringRequired

    Specifies billing frequency. Either day, week, month or year.

    Possible values
    • day
    • month
    • week
    • year
  • activeboolean

    Whether the plan is currently available for new subscriptions. Defaults to true.

  • amountinteger

    A positive integer in cents (or local equivalent) (or 0 for a free plan) representing how much to charge on a recurring basis.

  • amount_decimalstring

    Same as amount, but accepts a decimal value with at most 12 decimal places. Only one of amount and amount_decimal can be set.

  • billing_schemestring

    Describes how to compute the price per period. Either per_unit or tiered. per_unit indicates that the fixed amount (specified in amount) will be charged per unit in quantity (for plans with usage_type=licensed), or per unit of total usage (for plans with usage_type=metered). tiered indicates that the unit pricing will be computed using a tiering strategy as defined using the tiers and tiers_mode attributes.

    Possible values
    • per_unit
    • tiered
  • expandarray of strings

    Specifies which fields in the response should be expanded.

  • idstring

    An 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_countinteger

    The number of intervals between subscription billings. For example, interval=month and interval_count=3 bills every 3 months. Maximum of three years interval allowed (3 years, 36 months, or 156 weeks).

  • metadataobject

    Set 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.

  • meterstring

    The meter tracking the usage of a metered price

  • nicknamestring

    A brief description of the plan, hidden from customers.

  • productobject | string
    Show 7 child parameters
    • namestringRequired
    • activeboolean
    • idstring
    • metadataobject
    • statement_descriptorstring
    • tax_codestring
    • unit_labelstring
  • tiersarray of objects

    Each element represents a pricing tier. This parameter requires billing_scheme to be set to tiered. See also the documentation for billing_scheme.

    Show 5 child parameters
    • up_tostring | integerRequired
      Possible values
      • inf
    • flat_amountinteger
    • flat_amount_decimalstring
    • unit_amountinteger
    • unit_amount_decimalstring
  • tiers_modestring

    Defines if the tiering price should be graduated or volume based. In volume-based tiering, the maximum quantity within a period determines the per unit price, in graduated tiering pricing can successively change as the quantity grows.

    Possible values
    • graduated
    • volume
  • transform_usageobject

    Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with tiers.

    Show 2 child parameters
    • divide_byintegerRequired
    • roundstringRequired
      Possible values
      • down
      • up
  • trial_period_daysinteger

    Default number of trial days when subscribing a customer to this plan using trial_from_plan=true.

  • usage_typestring

    Configures how the quantity per period should be determined. Can be either metered or licensed. licensed automatically bills the quantity set when adding it to a subscription. metered aggregates the total usage based on usage records. Defaults to licensed.

    Possible values
    • licensed
    • metered

Returns

The plan object.

POST /v1/plans
curl https://api.knoxapi.com/v1/plans \
  -H "Authorization: Bearer $KNOX_SECRET_KEY" \
  -d currency=usd \
  -d interval=month
Response
{
  "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

  • activeboolean

    Only return plans that are active or inactive (e.g., pass false to list all inactive plans).

  • createdobject | integer

    A filter on the list, based on the object created field. 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
    • gtinteger
    • gteinteger
    • ltinteger
    • lteinteger
  • ending_beforestring

    A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_bar, your subsequent call can include ending_before=obj_bar in order to fetch the previous page of the list.

  • expandarray of strings

    Specifies which fields in the response should be expanded.

  • limitinteger

    A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.

  • productstring

    Only return plans for the given product.

  • starting_afterstring

    A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include starting_after=obj_foo in order to fetch the next page of the list.

Returns

A list of plan objects.

GET /v1/plans
curl -G https://api.knoxapi.com/v1/plans \
  -H "Authorization: Bearer $KNOX_SECRET_KEY" \
  --data-urlencode limit=3
Response
{
  "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

  • activeboolean

    Whether the plan is currently available for new subscriptions.

  • expandarray of strings

    Specifies which fields in the response should be expanded.

  • metadataobject

    Set 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.

  • nicknamestring

    A brief description of the plan, hidden from customers.

  • productstring

    The product the plan belongs to. This cannot be changed once it has been used in a subscription or subscription schedule.

  • trial_period_daysinteger

    Default number of trial days when subscribing a customer to this plan using trial_from_plan=true.

Returns

The plan object.

POST /v1/plans/{plan}
curl https://api.knoxapi.com/v1/plans/price_1PgafmB7WZ01zgkW6dKueIc5 \
  -H "Authorization: Bearer $KNOX_SECRET_KEY" \
  -d "metadata[order_id]=6735"
Response
{
  "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 strings

    Specifies which fields in the response should be expanded.

Returns

The plan object.

GET /v1/plans/{plan}
curl https://api.knoxapi.com/v1/plans/price_1PgafmB7WZ01zgkW6dKueIc5 \
  -H "Authorization: Bearer $KNOX_SECRET_KEY"
Response
{
  "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.

DELETE /v1/plans/{plan}
curl -X DELETE https://api.knoxapi.com/v1/plans/price_1PgafmB7WZ01zgkW6dKueIc5 \
  -H "Authorization: Bearer $KNOX_SECRET_KEY"
Response
{
  "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.