Skip to content
Join our SlackContact usGet started

Create Subscription

client.Subscriptions.New(ctx, body) (*SubscriptionNewResponse, error)
post/subscriptions

Create Subscription

ParametersExpand Collapse
body SubscriptionNewParams
CheckoutCallbackURLs param.Field[CheckoutCallback]

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

RateCardID param.Field[string]

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

SubjectID param.Field[string]

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

CreateCheckoutSession param.Field[SubscriptionNewParamsCreateCheckoutSession]optional

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

const SubscriptionNewParamsCreateCheckoutSessionWhenRequired SubscriptionNewParamsCreateCheckoutSession = "when_required"
const SubscriptionNewParamsCreateCheckoutSessionAlways SubscriptionNewParamsCreateCheckoutSession = "always"
Metadata param.Field[map[string, string]]optional

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

ReturnsExpand Collapse
type SubscriptionNewResponse struct{…}
Result SubscriptionNewResponseResultUnion

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:
type SubscriptionNewResponseResultRequiresAction struct{…}
Action SubscriptionNewResponseResultRequiresActionAction

The action to take to complete the request.

CheckoutURL string

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

RequiresActionType Checkout
Accepts one of the following:
const CheckoutCheckout Checkout = "checkout"
ResultType RequiresAction
Accepts one of the following:
const RequiresActionRequiresAction RequiresAction = "requires_action"
type SubscriptionNewResponseResultSuccess struct{…}
ResultType Success
Accepts one of the following:
const SuccessSuccess Success = "success"

The created subscription resource.

ID string

The ID of the subscription.

CancelsAtEndOfCycle bool

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

CurrentPeriod SubscriptionResourceCurrentPeriod

The current period of the subscription if it is active.

End Time
formatdate-time
Start Time
formatdate-time
InclusiveEnd booloptional
InclusiveStart booloptional
CyclesNextAt Time

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

formatdate-time
EffectiveAt Time

The date and time the subscription became effective.

formatdate-time
Metadata map[string, string]
RateCardID string

The ID of the rate card of the subscription.

Status SubscriptionResourceStatus

The status of the subscription.

Accepts one of the following:
const SubscriptionResourceStatusActive SubscriptionResourceStatus = "active"
const SubscriptionResourceStatusCancelled SubscriptionResourceStatus = "cancelled"
const SubscriptionResourceStatusPaused SubscriptionResourceStatus = "paused"
SubjectID string

The ID of the subject that the subscription is for.

Create Subscription
package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/-go"
  "github.com/stainless-sdks/-go/option"
)

func main() {
  client := lark.NewClient(
    option.WithAPIKey("My API Key"),
  )
  subscription, err := client.Subscriptions.New(context.TODO(), lark.SubscriptionNewParams{
    CheckoutCallbackURLs: lark.CheckoutCallbackParam{
      CancelledURL: "https://example.com/try-again",
      SuccessURL: "https://example.com/welcome",
    },
    RateCardID: "rc_AJWMxR81jxoRlli6p13uf3JB",
    SubjectID: "subj_VyX6Q96h5avMho8O7QWlKeXE",
    Metadata: map[string]string{
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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"
    }
  }
}