Skip to content
Join our SlackContact usGet started

Create Subscription

client.subscriptions.create(SubscriptionCreateParams { checkout_callback_urls, rate_card_id, subject_id, 2 more } body, RequestOptionsoptions?): SubscriptionCreateResponse { result }
post/subscriptions

Create Subscription

ParametersExpand Collapse
body: SubscriptionCreateParams { checkout_callback_urls, rate_card_id, subject_id, 2 more }
checkout_callback_urls: CheckoutCallback { cancelled_url, success_url }

The URLs to redirect to after the checkout is completed or cancelled, if a checkout is required.

cancelled_url: string

The URL to redirect to after the checkout is cancelled.

minLength1
formaturi
success_url: string

The URL to redirect to after the checkout is successful.

minLength1
formaturi
rate_card_id: string

The ID of the rate card to use for the subscription.

subject_id: string

The ID or external ID of the subject to create the subscription for.

create_checkout_session?: "when_required" | "always"

Determines whether a checkout session is always required even if the subject has a payment method on file. By default, if the subject has a payment method on file or the subscription is for a free plan, the subscription will be created and billed for immediately (if for a paid plan).

Accepts one of the following:
"when_required"
"always"
metadata?: Record<string, string>

Additional metadata about the subscription. You may use this to store any custom data about the subscription.

ReturnsExpand Collapse
SubscriptionCreateResponse { result }
result: CreateSubscriptionRequiresActionResponse { action, result_type } | CreateSubscriptionSuccessResponse { result_type, subscription }

The result of the request. If the request is successful, the subscription resource will be returned. If the request is requires action, the action to take to complete the request will be returned.

Accepts one of the following:
CreateSubscriptionRequiresActionResponse { action, result_type }
action: Action { checkout_url, requires_action_type }

The action to take to complete the request.

checkout_url: string

The URL of the checkout page to redirect to in order to complete the request.

requires_action_type: "checkout"
Accepts one of the following:
"checkout"
result_type: "requires_action"
Accepts one of the following:
"requires_action"
CreateSubscriptionSuccessResponse { result_type, subscription }
result_type: "success"
Accepts one of the following:
"success"
subscription: SubscriptionResource { id, cancels_at_end_of_cycle, current_period, 6 more }

The created subscription resource.

id: string

The ID of the subscription.

cancels_at_end_of_cycle: boolean

Whether the subscription will be cancelled at the end of the current cycle.

current_period: CurrentPeriod | null

The current period of the subscription if it is active.

end: string
formatdate-time
start: string
formatdate-time
inclusive_end?: boolean
inclusive_start?: boolean
cycles_next_at: string | null

The date and time the next cycle of the subscription will start.

formatdate-time
effective_at: string

The date and time the subscription became effective.

formatdate-time
metadata: Record<string, string>
rate_card_id: string

The ID of the rate card of the subscription.

status: "active" | "cancelled" | "paused"

The status of the subscription.

Accepts one of the following:
"active"
"cancelled"
"paused"
subject_id: string

The ID of the subject that the subscription is for.

Create Subscription
import Lark from 'lark-billing';

const client = new Lark({
  apiKey: 'My API Key',
});

const subscription = await client.subscriptions.create({
  checkout_callback_urls: {
    cancelled_url: 'https://example.com/try-again',
    success_url: 'https://example.com/welcome',
  },
  rate_card_id: 'rc_AJWMxR81jxoRlli6p13uf3JB',
  subject_id: 'subj_VyX6Q96h5avMho8O7QWlKeXE',
  metadata: {},
});

console.log(subscription.result);
{
  "result": {
    "result_type": "success",
    "subscription": {
      "id": "rc_sub_PuLvkNSP3IBCvjayBD3TXNQ6",
      "cancels_at_end_of_cycle": false,
      "current_period": {
        "end": "2025-11-01T00:00:00Z",
        "start": "2025-10-01T00:00:00Z",
        "inclusive_end": false,
        "inclusive_start": true
      },
      "cycles_next_at": "2025-11-01T00:00:00Z",
      "effective_at": "2025-10-01T00:00:00Z",
      "metadata": {},
      "rate_card_id": "rc_AJWMxR81jxoRlli6p13uf3JB",
      "status": "active",
      "subject_id": "subj_VyX6Q96h5avMho8O7QWlKeXE"
    }
  }
}
Returns Examples
{
  "result": {
    "result_type": "success",
    "subscription": {
      "id": "rc_sub_PuLvkNSP3IBCvjayBD3TXNQ6",
      "cancels_at_end_of_cycle": false,
      "current_period": {
        "end": "2025-11-01T00:00:00Z",
        "start": "2025-10-01T00:00:00Z",
        "inclusive_end": false,
        "inclusive_start": true
      },
      "cycles_next_at": "2025-11-01T00:00:00Z",
      "effective_at": "2025-10-01T00:00:00Z",
      "metadata": {},
      "rate_card_id": "rc_AJWMxR81jxoRlli6p13uf3JB",
      "status": "active",
      "subject_id": "subj_VyX6Q96h5avMho8O7QWlKeXE"
    }
  }
}