Introducing the Better Auth Chargebee plugin: Use it to handle subscriptions, billing, and auth seamlessly.
Chargebeechargebee API

Import a subscription

Idempotency Supported

Imports a subscription for an existing customer.

Use this operation when migrating subscriptions from another billing system.

Prerequisites & Constraints

  • Pause Subscription must be enabled for your site to import subscriptions with status set to paused.
  • At least one subscription_items[item_price_id] must reference an item price of type plan.

If you are calling this operation on your live site, ensure you have requested Support to enable it; otherwise the API may return an "API not enabled" error.

Impacts

Subscription

A subscription is created for the customer with the details provided in the request.

Invoice and payment

When create_current_term_invoice is true, an invoice is created for the current term.

Sample Request

Sample Result[JSON]

URL Format

POST https://[site].chargebee.com/api/v2/customers/{customer-id}/import_for_items

Input Parameters

exhausted_coupon_ids
optional, string, max chars=100

Specifies the IDs of coupons to be marked as exhausted. This parameter accepts a list of IDs, which must correspond to coupons with a duration_type of one_time. Ensure that the IDs included in this parameter do not match any IDs provided in the coupon_ids parameter.

id
optional, string, max chars=50

A unique and immutable identifier for the subscription. If not provided, it is autogenerated.

trial_end
optional, timestamp(UTC) in seconds

End of the trial period for the subscription. This overrides the trial period set for the plan-item. The value must be later than start_date. Set it to 0 to have no trial period.

Required if
  • trial_end is required when status is in_trial.
Constraints
  • trial_end must not be provided when status is future.
  • trial_end must be a future timestamp when status is in_trial.
billing_cycles
optional, integer, min=0

The number of billing cycles the subscription runs before canceling. If not provided, then the billing cycles set for the plan-item price is used.

Required if
  • billing_cycles is required when contract_term[action_at_term_end] is provided.
Constraints
  • billing_cycles must not be provided when status is cancelled.
  • billing_cycles must be at least 1, unless status is in_trial.
net_term_days
optional, integer

Defines Net D for the subscription. Net D is the number of days within which any invoice raised for the subscription must be paid.

  • If a value is provided: Net D is set explicitly for the subscription to the value provided. The value must be one among those defined in the site configuration.
  • If not provided: The attribute is not set and therefore not returned by the API. In this case, when an invoice is raised - whether now or later - the net_term_days defined at the customer level is considered. .
Prerequisite
  • Payment Terms for Subscriptions must be enabled for your site to provide net_term_days.
Constraints
  • net_term_days is not allowed when auto_collection is on, unless Net Term Days for online payment methods is enabled for your site.
  • net_term_days is not allowed when auto_collection is off, unless Net Term Days for offline payment methods is enabled for your site.
start_date
optional, timestamp(UTC) in seconds

The date/time at which the subscription is to start or has started. If not provided, the subscription starts immediately.

Required if
  • start_date is required when status is future.
Constraints
  • start_date must be a future timestamp when status is future.
  • start_date must not be provided when status is in_trial.
auto_collection
optional, enumerated string

Defines whether payments need to be collected automatically for this subscription. Overrides customer's auto-collection property.

Enum Values
on

Whenever an invoice is created for this subscription, an automatic charge will be attempted on the payment method available.

off

Automatic collection of charges will not be made for this subscription. Use this for offline payments.

po_number
optional, string, max chars=100

Purchase order number for this subscription.

coupon_ids
optional, string, max chars=100

List of coupons to be applied to this subscription. You can provide coupon ids or coupon codes .

payment_source_id
optional, string, max chars=40

Id of the payment source to be attached to this subscription.

status
required, enumerated string

Current state of the subscription.

Constraint
  • status cannot be set to transferred when importing a subscription.
Enum Values
future

The subscription is scheduled to start at a future date.

in_trial

The subscription is in trial.

active

The subscription is active and will be charged for automatically based on the items in it.

non_renewing

The subscription will be canceled at the end of the current term.

paused

The subscription is paused. The subscription will not renew while in this state.

cancelled

The subscription has been canceled and is no longer in service.

transferred

The subscription has been transferred to another business entity within the organization.

current_term_end
optional, timestamp(UTC) in seconds

End of the current billing term. Subscription is renewed immediately after this. If not given, this will be calculated based on plan billing cycle.

Required if
  • current_term_end is required when status is active or non_renewing.
  • current_term_end is required when status is paused.
Constraints
  • current_term_end must not be provided when status is future.
  • current_term_end must not be provided when status is in_trial.
current_term_start
optional, timestamp(UTC) in seconds

Start of the current billing period of the subscription. This is required when the subscription status is paused. When the status is active or non_renewing , it defaults to the current time.

Required if
  • current_term_start is required when status is paused.
Constraints
  • current_term_start must not be provided when status is future.
  • current_term_start must not be provided when status is in_trial.
trial_start
optional, timestamp(UTC) in seconds

Start of the trial period for the subscription. When not passed, it is assumed to be current time. When passed for a future subscription, it implies that the subscription goes into in_trial when it starts.

Constraints
  • trial_start must not be provided when status is future.
  • trial_start must be in the past when status is in_trial.
cancelled_at
optional, timestamp(UTC) in seconds

Time at which subscription was cancelled or is set to be cancelled.

Required if
  • cancelled_at is required when status is cancelled.
Constraints
  • cancelled_at must not be provided when status is future.
  • cancelled_at must not be provided when status is in_trial.
started_at
optional, timestamp(UTC) in seconds

Time at which the subscription was started. Is null for future subscriptions as it is yet to be started.

Constraints
  • started_at must not be provided when status is future.
  • started_at must not be later than trial_start when status is in_trial.
activated_at
optional, timestamp(UTC) in seconds

The time at which the subscription was activated. A subscription is "activated" when its status changes from any other, to either active or non_renewing.

Constraints
  • activated_at must not be provided when status is future.
  • activated_at must be earlier than trial_start when status is in_trial.
pause_date
optional, timestamp(UTC) in seconds

When a pause has been scheduled, it is the date/time of scheduled pause. When the subscription is in the paused state, it is the date/time when the subscription was paused.

Required if
  • pause_date is required when status is paused.
Constraints
  • pause_date must not be provided when status is future.
  • pause_date must not be provided when status is in_trial.
resume_date
optional, timestamp(UTC) in seconds

For a paused subscription, it is the date/time when the subscription is scheduled to resume. If the pause is for an indefinite period, this value is not returned.

Constraints
  • resume_date must not be provided when status is future.
  • resume_date must not be provided when status is in_trial.
contract_term_billing_cycle_on_renewal
optional, integer, min=1, max=100

Number of billing cycles the new contract term should run for, on contract renewal. The default value is the same as billing_cycles or a custom value depending on the site configuration .

Required if
  • contract_term_billing_cycle_on_renewal is required when contract_term[action_at_term_end] is renew or renew_once.
Prerequisite
  • Contract Terms must be enabled for your site to provide contract_term_billing_cycle_on_renewal.
Constraints
  • contract_term_billing_cycle_on_renewal must not be provided when contract_term[action_at_term_end] is cancel or evergreen.
  • contract_term_billing_cycle_on_renewal requires contract_term[action_at_term_end] to be provided.
create_current_term_invoice
optional, boolean, default=false

Set as true if you want an invoice to be created for the subscription.

  • The invoice will be created for the subscription only if it has an active or non_renewing status.
  • The period of the invoice is from current_term_start to current_term_end.
  • The invoice will not be generated if the subscription amount is zero dollars (for that period) and 'Hide Zero Value Line Items' option is enabled in site settings.
  • You may pass transaction details to record an offline payment against that invoice.
Constraint
  • create_current_term_invoice can be true only when status is active or non_renewing.
invoice_notes
optional, string, max chars=2000

A customer-facing note added to all invoices associated with this subscription. This note is one among all the notes displayed on the invoice PDF.

meta_data
optional, jsonobject

A set of key-value pairs stored as additional information for the subscription. Learn more .

cancel_reason_code
optional, string, max chars=100

Reason code for canceling the subscription. Must be one from a list of reason codes set in the Chargebee app in Settings > Configure Chargebee > Reason Codes > Subscriptions > Subscription Cancellation. Must be passed if set as mandatory in the app. The codes are case-sensitive.

Constraint
  • cancel_reason_code must not be provided when status is future, in_trial, active, non_renewing, or paused.
create_pending_invoices
optional, boolean

Indicates whether the invoices for this subscription are generated with a pending status. This attribute is set to true automatically when the subscription has item prices that belong to metered items. You can also set this to true explicitly using the create/update subscription operations. This is useful in the following scenarios:

  • When tracking usages and calculating usage-based charges on your end. You can then add them to the subscription as a one-time charge at the end of the billing term.
  • When you need to inspect all charges before closing invoices for this subscription. Applicable only when Metered Billing is enabled for the site .
Prerequisite
  • Metered Billing must be enabled for your site to provide create_pending_invoices.
auto_close_invoices
optional, boolean

Set to false to override for this subscription, the site-level setting for auto-closing invoices. Only applicable when auto-closing invoices has been enabled for the site. This attribute has a higher precedence than the same attribute at the customer level .

Prerequisite
  • Metered Billing must be enabled for your site to provide auto_close_invoices.
contract_term
Parameters for contract_term
pass parameters as contract_term[<param name>]
transaction
Parameters for transaction
pass parameters as transaction[<param name>]
shipping_address
Parameters for shipping_address
pass parameters as shipping_address[<param name>]
subscription_items[0..n]
Parameters for subscription_items. Multiple subscription_items can be passed by specifying unique indices.
pass parameters as subscription_items[<param name>][<idx:0..n>]
discounts[0..n]
Parameters for discounts. Multiple discounts can be passed by specifying unique indices.
pass parameters as discounts[<param name>][<idx:0..n>]
charged_items[0..n]
Parameters for charged_items. Multiple charged_items can be passed by specifying unique indices.
pass parameters as charged_items[<param name>][<idx:0..n>]
item_tiers[0..n]
Parameters for item_tiers. Multiple item_tiers can be passed by specifying unique indices.
pass parameters as item_tiers[<param name>][<idx:0..n>]

Returns

Subscription object
Resource object representing subscription
Customer object
Resource object representing customer
Card object
Resource object representing card
Invoice object
Resource object representing invoice