Skip to content
Book a demoContact usGet started

Create Subscription

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

Create Subscription

ParametersExpand Collapse
body SubscriptionNewParams
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.

CheckoutCallbackURLs param.Field[CheckoutCallback]optional

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

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"
FixedRateQuantities param.Field[map[string, SubscriptionNewParamsFixedRateQuantityUnion]]optional

The quantities of the fixed rates to use for the subscription. Each quantity should be specified as a key-value pair, where the key is the code of the fixed rate and the value is the quantity. All fixed rates must have a quantity specified.

float64
string
Metadata param.Field[map[string, string]]optional

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

RatePriceMultipliers param.Field[map[string, SubscriptionNewParamsRatePriceMultiplierUnion]]optional

Pricing multipliers to apply to the rate amounts. Each price multiplier should be specified as a key-value pair, where the key is the code of the rate and the value is the price multiplier. Typically, pricing multipliers are used to apply a discount to a rate. For example, if a rate is $10 per seat and the price multiplier for the seats rate is 0.5, the discounted rate amount will be $5 per seat.

float64
string
SubscriptionTimelineID param.Field[string]optional

The ID of the subscription timeline to use for 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
ResultType RequiresAction
type SubscriptionNewResponseResultSuccess struct{…}
ResultType 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
FixedRateQuantities map[string, string]

The quantities of the fixed rates of the subscription.

Metadata map[string, string]
RateCardID string

The ID of the rate card of the subscription.

RatePriceMultipliers map[string, string]

The price multipliers of the rates 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/lark-go"
  "github.com/stainless-sdks/lark-go/option"
)

func main() {
  client := lark.NewClient(
    option.WithAPIKey("My API Key"),
  )
  subscription, err := client.Subscriptions.New(context.TODO(), lark.SubscriptionNewParams{
    RateCardID: "rc_AJWMxR81jxoRlli6p13uf3JB",
    SubjectID: "subj_VyX6Q96h5avMho8O7QWlKeXE",
    CheckoutCallbackURLs: lark.CheckoutCallbackParam{
      CancelledURL: "https://example.com/try-again",
      SuccessURL: "https://example.com/welcome",
    },
    FixedRateQuantities: map[string]lark.SubscriptionNewParamsFixedRateQuantityUnion{
    "seats": lark.SubscriptionNewParamsFixedRateQuantityUnion{
      OfString: lark.String("2"),
    },
    "addon_storage": lark.SubscriptionNewParamsFixedRateQuantityUnion{
      OfString: lark.String("0"),
    },
    },
    Metadata: map[string]string{
    },
    RatePriceMultipliers: map[string]lark.SubscriptionNewParamsRatePriceMultiplierUnion{
    "seats": lark.SubscriptionNewParamsRatePriceMultiplierUnion{
      OfString: lark.String("0.5"),
    },
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", subscription.Result)
}
{
  "result": {
    "action": {
      "checkout_url": "checkout_url",
      "requires_action_type": "checkout"
    },
    "result_type": "requires_action"
  }
}
Returns Examples
{
  "result": {
    "action": {
      "checkout_url": "checkout_url",
      "requires_action_type": "checkout"
    },
    "result_type": "requires_action"
  }
}