Create a portal session 

Billing
Customer Portal Session
Create a portal session

Creates a session of the customer portal.

Parameters

  • customerstringRequired

    The ID of an existing customer.

  • configurationstring

    The ID of an existing configuration to use for this session, describing its functionality and features. If not specified, the session uses the default configuration.

  • flow_dataobject

    Information about a specific flow for the customer to go through. See the docs to learn more about using customer portal deep links and flows.

    • flow_data.typeenumRequired

      Type of flow that the customer will go through.

      Possible enum values
      payment_method_update

      Customer will be able to add a new payment method. The payment method will be set as the customer.invoice_settings.default_payment_method.

      subscription_cancel

      Customer will be able to cancel their subscription.

      subscription_update

      Customer will be able to select prices to update to based on the configuration’s features.subscription_update.

      subscription_update_confirm

      Customer will be able to confirm a specified subscription update.

    • flow_data.after_completionobject

      Behavior after the flow is completed.

      • flow_data.after_completion.typeenumRequired

        The specified behavior after the flow is completed.

        Possible enum values
        hosted_confirmation

        Displays a confirmation message on the hosted surface after the flow is complete

        portal_homepage

        Redirects to the portal homepage after the flow is complete.

        redirect

        Redirects the customer to the specified redirect.return_url after the flow is complete.

      • flow_data.after_completion.hosted_confirmationobject

        Configuration when after_completion.type=hosted_confirmation.

        • flow_data.after_completion.hosted_confirmation.custom_messagestring

          A custom message to display to the customer after the flow is completed.

      • flow_data.after_completion.redirectobject

        Configuration when after_completion.type=redirect.

        • flow_data.after_completion.redirect.return_urlstringRequired

          The URL the customer will be redirected to after the flow is completed.

    • flow_data.subscription_cancelobjectRequired if type=subscription_cancel.

      Configuration when flow_data.type=subscription_cancel.

      • flow_data.subscription_cancel.subscriptionstringRequired

        The ID of the subscription to be canceled.

      • flow_data.subscription_cancel.retentionobject

        Specify a retention strategy to be used in the cancellation flow.

        • flow_data.subscription_cancel.retention.coupon_offerobjectRequired if type=coupon_offer.

          Configuration when retention.type=coupon_offer.

          • flow_data.subscription_cancel.retention.coupon_offer.couponstringRequired

            The ID of the coupon to be offered.

        • flow_data.subscription_cancel.retention.typeenumRequired

          Type of retention strategy to use with the customer.

          Possible enum values
          coupon_offer
    • flow_data.subscription_updateobjectRequired if type=subscription_update.

      Configuration when flow_data.type=subscription_update.

      • flow_data.subscription_update.subscriptionstringRequired

        The ID of the subscription to be updated.

    • flow_data.subscription_update_confirmobjectRequired if type=subscription_update_confirm.

      Configuration when flow_data.type=subscription_update_confirm.

      • flow_data.subscription_update_confirm.itemsarray of objectsRequired

        The subscription item to be updated through this flow. Currently, only up to one may be specified and subscriptions with multiple items are not updatable.

        • flow_data.subscription_update_confirm.items.idstringRequired

          The ID of the subscription item to be updated.

        • flow_data.subscription_update_confirm.items.pricestring

          The price the customer should subscribe to through this flow. The price must also be included in the configuration’s features.subscription_update.products.

        • flow_data.subscription_update_confirm.items.quantityinteger

          Quantity for this item that the customer should subscribe to through this flow.

      • flow_data.subscription_update_confirm.subscriptionstringRequired

        The ID of the subscription to be updated.

      • flow_data.subscription_update_confirm.discountsarray of objects

        The coupon or promotion code to apply to this subscription update.

        • flow_data.subscription_update_confirm.discounts.couponstring

          The ID of the coupon to apply to this subscription update.

        • flow_data.subscription_update_confirm.discounts.promotion_codestring

          The ID of a promotion code to apply to this subscription update.

  • localeenum

    The IETF language tag of the locale customer portal is displayed in. If blank or auto, the customer’s preferred_locales or browser’s locale is used.

  • on_behalf_ofstringConnect only

    The on_behalf_of account to use for this session. When specified, only subscriptions and invoices with this on_behalf_of account appear in the portal. For more information, see the docs. Use the Accounts API to modify the on_behalf_of account’s branding settings, which the portal displays.

  • return_urlstring

    The default URL to redirect customers to when they click on the portal’s link to return to your website.

Returns

Returns a portal session object.

POST /v1/billing_portal/sessions
curl https://api.stripe.com/v1/billing_portal/sessions \
-u "sk_test_BQokikJ...2HlWgH4olfQ2sk_test_BQokikJOvBiI2HlWgH4olfQ2:" \
-d customer=cus_NciAYcXfLnqBoz \
--data-urlencode return_url="https://example.com/account"
Response
{
"id": "bps_1MrSjzLkdIwHu7ixex0IvU9b",
"object": "billing_portal.session",
"configuration": "bpc_1MAhNDLkdIwHu7ixckACO1Jq",
"created": 1680210639,
"customer": "cus_NciAYcXfLnqBoz",
"flow": null,
"livemode": false,
"locale": null,
"on_behalf_of": null,
"return_url": "https://example.com/account",
"url": "https://billing.stripe.com/p/session/test_YWNjdF8xTTJKVGtMa2RJd0h1N2l4LF9OY2lBYjJXcHY4a2NPck96UjBEbFVYRnU5bjlwVUF50100BUtQs3bl"
}