# Create pricing page for new subscription

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

This endpoint streamlines the generation of a pricing page session to enable new subscription creation workflows using Chargebee's hosted pricing pages ([Atomic Pricing](https://www.atomicpricing.com/) ). By providing a subscription ID and/or customer ID as a parameter, you'll obtain a pricing page session URL.

Note: [Full access key](https://www.chargebee.com/docs/api_keys.html#types-of-api-keys_full-access-key) authentication is needed for this API request.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/pricing_page_sessions/create_for_new_subscription \
     -u {site_api_key}:\
     -d "pricing_page[id]"="01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q" \
     -d "subscription[id]"="__test__KyVnHhSBWmCoF2tJ" \
     -d "customer[id]"="__test__8asqlU6yBgeA3k"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PricingPageSession.CreateForNewSubscription()
		.PricingPageId("01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q")
		.SubscriptionId("__test__KyVnHhSBWmCoF2tJ")
		.CustomerId("__test__8asqlU6yBgeA3k")
		.Request();

PricingPageSession pricingPageSession = result.PricingPageSession;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    pricingpagesessionAction "github.com/chargebee/chargebee-go/v3/actions/pricingpagesession"
    "github.com/chargebee/chargebee-go/v3/models/pricingpagesession"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := pricingpagesessionAction.CreateForNewSubscription(&pricingpagesession.CreateForNewSubscriptionRequestParams{
        PricingPage : &pricingpagesession.CreateForNewSubscriptionPricingPageParams{
            Id : "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q",
        },
        Subscription : &pricingpagesession.CreateForNewSubscriptionSubscriptionParams{
            Id : "__test__KyVnHhSBWmCoF2tJ",
        },
        Customer : &pricingpagesession.CreateForNewSubscriptionCustomerParams{
            Id : "__test__8asqlU6yBgeA3k",
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        PricingPageSession := res.PricingPageSession
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PricingPageSessionCreateForNewSubscriptionRequest{
    PricingPage : &chargebee.PricingPageSessionCreateForNewSubscriptionPricingPage{
        Id : "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q",
    },
    Subscription : &chargebee.PricingPageSessionCreateForNewSubscriptionSubscription{
        Id : "__test__KyVnHhSBWmCoF2tJ",
    },
    Customer : &chargebee.PricingPageSessionCreateForNewSubscriptionCustomer{
        Id : "__test__8asqlU6yBgeA3k",
    },
}
  res, err := client.PricingPageSession.CreateForNewSubscription(req)
      if err != nil {
        fmt.Println(err)
    } else {
        PricingPageSession := res.PricingPageSession
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = PricingPageSession.createForNewSubscription()
            .pricingPageId("01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q")
            .subscriptionId("__test__KyVnHhSBWmCoF2tJ")
            .customerId("__test__8asqlU6yBgeA3k")
            .request();

        PricingPageSession pricingPageSession = result.pricingPageSession();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.pricingPageSession.PricingPageSession;
import com.chargebee.v4.models.pricingPageSession.params.PricingPageSessionCreateForNewSubscriptionParams;
import com.chargebee.v4.models.pricingPageSession.responses.PricingPageSessionCreateForNewSubscriptionResponse;

public class PricingPageSessionCreateForNewSubscription {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PricingPageSessionCreateForNewSubscriptionParams.PricingPageParams pricingPageParams =
            PricingPageSessionCreateForNewSubscriptionParams.PricingPageParams.builder()
                .id("01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q")
                .build();

        PricingPageSessionCreateForNewSubscriptionParams.SubscriptionParams subscriptionParams =
            PricingPageSessionCreateForNewSubscriptionParams.SubscriptionParams.builder()
                .id("__test__KyVnHhSBWmCoF2tJ")
                .build();

        PricingPageSessionCreateForNewSubscriptionParams.CustomerParams customerParams =
            PricingPageSessionCreateForNewSubscriptionParams.CustomerParams.builder()
                .id("__test__8asqlU6yBgeA3k")
                .build();

        PricingPageSessionCreateForNewSubscriptionParams params = PricingPageSessionCreateForNewSubscriptionParams.builder()
            .pricingPage(pricingPageParams)
            .subscription(subscriptionParams)
            .customer(customerParams)
            .build();

        PricingPageSessionCreateForNewSubscriptionResponse response = client.pricingPageSessions().createForNewSubscription(params);

        PricingPageSession pricingPageSession = response.getPricingPageSession();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.pricingPageSession.createForNewSubscription({
        pricing_page: {
            id: "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
        },
        subscription: {
            id: "__test__KyVnHhSBWmCoF2tJ"
        },
        customer: {
            id: "__test__8asqlU6yBgeA3k"
        }
    });

    console.log(result);
    const pricingPageSession = result.pricing_page_session;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->pricingPageSession()->createForNewSubscription([
    "pricing_page" => [
        "id" => "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
    ],
    "subscription" => [
        "id" => "__test__KyVnHhSBWmCoF2tJ"
    ],
    "customer" => [
        "id" => "__test__8asqlU6yBgeA3k"
    ]
]);
$pricingPageSession = $result->pricing_page_session;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.PricingPageSession.create_for_new_subscription(
    cb_client.PricingPageSession.CreateForNewSubscriptionParams(
        pricing_page=cb_client.PricingPageSession.CreateForNewSubscriptionPricingPageParams(
            id="01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
        ),
        subscription=cb_client.PricingPageSession.CreateForNewSubscriptionSubscriptionParams(
            id="__test__KyVnHhSBWmCoF2tJ"
        ),
        customer=cb_client.PricingPageSession.CreateForNewSubscriptionCustomerParams(
            id="__test__8asqlU6yBgeA3k"
        )
    )
)
pricing_page_session = response.pricing_page_session
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::PricingPageSession.create_for_new_subscription({
  :pricing_page => {
    :id => "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
  },
  :subscription => {
    :id => "__test__KyVnHhSBWmCoF2tJ"
  },
  :customer => {
    :id => "__test__8asqlU6yBgeA3k"
  }
})

pricing_page_session = result.pricing_page_session
```

## Sample Response

```json
{
  "pricing_page_session": {
    "id": "__test__VZlifqcdrl4Itq1go1b5lZY5cu2OJYYaNp",
    "url": "https://hosted.atomicpricing.com/sites/01HTPJMZXNJ2CGQ9FP6W2BJA9B/pricing-session/__test__VZlifqcdrl4Itq1go1b5lZY5cu2OJYYaNp",
    "created_at": 1709792318,
    "expires_at": 1709795918,
    "object": "pricing_page_session"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/pricing_page_sessions/create_for_new_subscription

## Input Parameters

- `redirect_url` (optional, string, max chars=250)
  The customers will be redirected to this URL upon successful checkout.

- `business_entity_id` (optional, string, max chars=50)
  Sets the [context](/docs/api/business_entities) for this operation to the [business entity](/docs/api/business_entities) specified. Applicable only when multiple business entities have been created for the site. When this parameter is provided, new subscription and customer resources are created within the business entity.

- `brand_id` (optional, string, max chars=50)
  The unique ID of the [brand](/docs/api/brands) this pricing page session should be linked to. Applicable only when multiple brands have been created for the site. The customer and subscription created through the session are linked to the same brand. An alternative way of passing this parameter is by means of the `chargebee-brand-id` custom HTTP header; when both are provided, they must specify the same brand.
  
  **Default behavior**
  
  -   When not provided, the default brand defined for the site is used.

- `auto_select_local_currency` (optional, boolean, default=false)
  -   **`false`:** The first currency in the dropdown list is selected.
  -   **`true`:** Automatically determines the currency based on the visitor's geolocation. For example, if the visitor is from the United States and this flag is enabled, USD is selected as the currency-if it's available on the pricing page. Similarly, if the visitor is from India, INR is selected. If the visitor's country currency isn't available, the first currency in the dropdown list is selected.

- `custom` (optional, jsonobject)
  JSON object of custom attributes (key-value pairs) used for pricing page targeting or content. [Configure](https://www.chargebee.com/docs/retention/settings-and-installation/chargebee-retention-field-mappings) custom attributes in the dashboard.

- `pricing_page` (optional, string)
  Parameters for pricing page
  - `id` (optional, string, max chars=50)
    The unique identifier of the pricing table for which the hosted page is created. See [documentation](https://www.chargebee.com/docs/growth/offers/customize-pricing-table#obtain-the-pricing-table-id) to obtain the pricing table id from Chargebee Growth. If you want the pricing table to be auto-selected based on your [Play configuration](https://www.chargebee.com/docs/growth/plays/plays-overview) in Chargebee Growth, do not pass this parameter.
    
    **Required if**
    
    -   You are on the legacy version of Pricing Tables (i.e. Atomic Pricing). See [documentation](https://www.chargebee.com/docs/billing/2.0/hosted-capabilities/customize-pricing-table#obtain-the-site-id-and-pricing-table-id) to obtain the pricing table id.
    -   Chargebee Growth is enabled for your site and either `customer[id]` is not provided or it does not identify an existing customer.

- `subscription` (optional, string)
  Parameters for subscription
  - `id` (optional, string, max chars=50)
    A unique and immutable identifier for the subscription. If not provided, it is autogenerated.

- `customer` (optional, string)
  Parameters for customer
  - `id` (optional, string, max chars=50)
    The unique ID of the customer for which this `hosted_page` should be created. When not provided, a new customer is created with the ID set to the value provided for `subscription[id]`. If `subscription[id]` is unavailable, then the customer ID is autogenerated.
    
    **Required if**
    
    -   Chargebee Growth is enabled for your site and `pricing_page[id]` is not provided.
    
    **Constraints**
    
    -   For Chargebee Growth auto-selection, when `pricing_page[id]` is not provided, must identify an existing customer in Chargebee. If the customer does not exist, the API returns a `resource_not_found` error.
  - `email` (optional, string, max chars=70)
    Email of the customer. Configured email notifications will be sent to this email.
  - `first_name` (optional, string, max chars=150)
    First name of the customer. If not provided it will be got from contact information entered in the hosted page
  - `last_name` (optional, string, max chars=150)
    Last name of the customer. If not provided it will be got from contact information entered in the hosted page
  - `company` (optional, string, max chars=250)
    Company name of the customer.
  - `phone` (optional, string, max chars=50)
    Phone number of the customer
  - `locale` (optional, string, max chars=50)
    Determines which region-specific language Chargebee uses to communicate with the customer. In the absence of the locale attribute, Chargebee will use your site's default language for customer communication.

- `billing_address` (optional, string)
  Parameters for billing\_address
  - `first_name` (optional, string, max chars=150)
    The first name of the billing contact.
  - `last_name` (optional, string, max chars=150)
    The last name of the billing contact.
  - `email` (optional, string, max chars=70)
    The email address.
  - `company` (optional, string, max chars=250)
    The company name.
  - `phone` (optional, string, max chars=50)
    The phone number.
  - `line1` (optional, string, max chars=150)
    Address line 1
  - `line2` (optional, string, max chars=150)
    Address line 2
  - `line3` (optional, string, max chars=150)
    Address line 3
  - `city` (optional, string, max chars=50)
    The name of the city.
  - `state_code` (optional, string, max chars=50)
    The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search/code) without the country prefix. Currently supported for USA, Canada and India. For instance, for Arizona (USA), set `state_code` as `AZ` (not `US-AZ` ). For Tamil Nadu (India), set as `TN` (not `IN-TN` ). For British Columbia (Canada), set as `BC` (not `CA-BC` ).
  - `state` (optional, string, max chars=50)
    The state/province name. Is set by Chargebee automatically for US, Canada and India If `state_code` is provided.
  - `zip` (optional, string, max chars=20)
    Zip or postal code. The number of characters is validated according to the rules [specified here](https://chromium-i18n.appspot.com/ssl-address) .
  - `country` (optional, string, max chars=50)
    The billing address country of the customer. Must be one of [ISO 3166 alpha-2 country code](https://www.iso.org/iso-3166-country-codes.html) .
    
    **Note**: If you enter an invalid country code, the system will return an error.
    
    **Brexit**
    
    If you have enabled [EU VAT](https://www.chargebee.com/docs/eu-vat.html) in 2021 or later, or have [manually enable](https://www.chargebee.com/docs/brexit.html#what-needs-to-be-done-in-chargebee) the Brexit configuration, then `XI` (the code for **United Kingdom - Northern Ireland**) is available as an option.
  - `validation_status` (optional, enumerated string, default=not_validated)
    The address verification status.
    Possible enum values:
      - `not_validated`
        Address is not yet validated.
      - `valid`
        Address was validated successfully.
      - `partially_valid`
        The address is valid for taxability but has not been validated for shipping.
      - `invalid`
        Address is invalid.

- `shipping_address` (optional, string)
  Parameters for shipping\_address
  - `first_name` (optional, string, max chars=150)
    The first name of the contact.
  - `last_name` (optional, string, max chars=150)
    The last name of the contact.
  - `email` (optional, string, max chars=70)
    The email address.
  - `company` (optional, string, max chars=250)
    The company name.
  - `phone` (optional, string, max chars=50)
    The phone number.
  - `line1` (optional, string, max chars=150)
    Address line 1
  - `line2` (optional, string, max chars=150)
    Address line 2
  - `line3` (optional, string, max chars=150)
    Address line 3
  - `city` (optional, string, max chars=50)
    The name of the city.
  - `state_code` (optional, string, max chars=50)
    The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search/code) without the country prefix. Currently supported for USA, Canada and India. For instance, for Arizona (USA), set `state_code` as `AZ` (not `US-AZ` ). For Tamil Nadu (India), set as `TN` (not `IN-TN` ). For British Columbia (Canada), set as `BC` (not `CA-BC` ).
  - `state` (optional, string, max chars=50)
    The state/province name. Is set by Chargebee automatically for US, Canada and India If `state_code` is provided.
  - `zip` (optional, string, max chars=20)
    Zip or postal code. The number of characters is validated according to the rules [specified here](https://chromium-i18n.appspot.com/ssl-address) .
  - `country` (optional, string, max chars=50)
    The billing address country of the customer. Must be one of [ISO 3166 alpha-2 country code](https://www.iso.org/iso-3166-country-codes.html) .
    
    **Note**: If you enter an invalid country code, the system will return an error.
    
    **Brexit**
    
    If you have enabled [EU VAT](https://www.chargebee.com/docs/eu-vat.html) in 2021 or later, or have [manually enable](https://www.chargebee.com/docs/brexit.html#what-needs-to-be-done-in-chargebee) the Brexit configuration, then `XI` (the code for **United Kingdom - Northern Ireland**) is available as an option.
  - `validation_status` (optional, enumerated string, default=not_validated)
    The address verification status.
    Possible enum values:
      - `not_validated`
        Address is not yet validated.
      - `valid`
        Address was validated successfully.
      - `partially_valid`
        The address is valid for taxability but has not been validated for shipping.
      - `invalid`
        Address is invalid.

- `contract_term` (optional, enumerated string)
  Parameters for contract\_term
  - `action_at_term_end` (optional, enumerated string, default=renew)
    Action to be taken when the contract term completes.
    Possible enum values:
      - `renew`
        -   Contract term completes and a new contract term is started for the default number of billing cycles.
        -   The `action_at_term_end` for the new contract term is set to `renew`.
      - `evergreen`
        Contract term completes and the subscription renews.
      - `cancel`
        Contract term completes and subscription is canceled.
      - `renew_once`
        Used when you want to renew the contract term just once. Does the following:
        
        -   Contract term completes and a new contract term is started for the number of billing cycles specified in [`contract_term_billing_cycle_on_renewal`](/docs/api/subscriptions/create-subscription-for-items#contract_term_billing_cycle_on_renewal).
        -   The `action_at_term_end` for the new contract term is set to `cancel`.
  - `cancellation_cutoff_period` (optional, integer, default=0)
    The number of days before [`contract_end`](/docs/api/contract_terms/contract_term-object#contract_end) , during which the customer is barred from canceling the contract term. The customer is allowed to cancel the contract term via the Self-Serve Portal only before this period. This allows you to have sufficient time for processing the contract term closure.

- `discounts` (optional, array)
  Parameters for discounts
  - `apply_on` (optional, enumerated string)
    The amount on the invoice to which the discount is applied.
    Possible enum values:
      - `invoice_amount`
        The discount is applied to the invoice `sub_total`.
        
        **Note:** This enum value is not supported for `pricing_page_sessions` resource, soon this value will be available for this resource. For more details please reach out to [atomic-pricing@chargebee.com](mailto:atomic-pricing@chargebee.com)
      - `specific_item_price`
        The discount is applied to the `invoice.line_item.amount` that corresponds to the item price specified by `item_price_id` .
  - `duration_type` (required, enumerated string)
    Specifies the time duration for which this discount is attached to the subscription.
    Possible enum values:
      - `one_time`
        The discount stays attached to the subscription till it is applied on an invoice **once**. It is removed after that from the subscription.
      - `forever`
        The discount is attached to the subscription and applied on the invoices till it is [explicitly removed](/docs/api/subscriptions/update-subscription-for-items#discounts_operation_type) .
      - `limited_period`
        The discount is attached to the subscription and applied on the invoices for a limited duration. This duration starts from the point it is applied to an invoice for the first time and expires after a period specified by `period` and `period_unit` .
  - `percentage` (optional, double)
    The percentage of the original amount that should be deducted from it.
  - `amount` (optional, in cents)
    The value of the discount. The format of this value depends on the kind of [currency](/docs/api/currencies) you want to use for a discount. This is only applicable when [`type`](/docs/api/discounts/discount-object#type) is `fixed_amount` .
  - `period` (optional, integer)
    The duration of time for which the discount is attached to the subscription, in `period_units`. Applicable only when `duration_type` is `limited_period` .
  - `period_unit` (optional, enumerated string)
    The unit of time for `period`. Applicable only when `duration_type` is `limited_period` .
    Possible enum values:
      - `day`
        A period of 24 hours.
      - `week`
        A period of 7 days.
      - `month`
        A period of 1 calendar month.
      - `year`
        A period of 1 calendar year.
  - `included_in_mrr` (optional, boolean)
    The discount is included in MRR calculations for your site. This attribute is only applicable when `duration_type` is `one_time` and when the [feature is enabled](https://www.chargebee.com/docs/reporting.html#dashboards_flexible-mrr-calculation) in Chargebee. Also, If the [site-level setting](https://www.chargebee.com/docs/reporting.html#chart_flexible-mrr-calculation) is to exclude one-time discounts from MRR calculations, this value is always returned `false` .
  - `item_price_id` (optional, string, max chars=100)
    The [id of the item price](/docs/api/subscriptions/subscription-object#subscription_items_item_price_id) in the subscription to which the discount is to be applied. Relevant only when [`apply_on`](/docs/api/discounts/discount-object#apply_on) is `specific_item_price` .
  - `quantity` (optional, integer)
    Specifies the number of free units provided for the item, without affecting the total quantity sold
  - `label` (optional, string, max chars=100)
    Label for the discount

## Returns

- `pricing_page_session` (Pricing page session object)
  Resource object representing pricing\_page\_session
