# Create pricing page for existing 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 subscription [upgrade](https://www.chargebee.com/docs/2.0/proration.html#introduction_proration) , and [downgrade](https://www.chargebee.com/docs/2.0/proration.html#introduction_proration) workflows using Chargebee's hosted pricing pages ([Atomic Pricing](https://www.atomicpricing.com/) ). By providing a subscription ID as a parameter, you will obtain a hosted 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_existing_subscription \
     -u {site_api_key}:\
     -d "pricing_page[id]"="01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q" \
     -d "subscription[id]"="__test__KyVnHhSBWmCoF2tJ"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = PricingPageSession.CreateForExistingSubscription()
		.PricingPageId("01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q")
		.SubscriptionId("__test__KyVnHhSBWmCoF2tJ")
		.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.CreateForExistingSubscription(&pricingpagesession.CreateForExistingSubscriptionRequestParams{
        PricingPage : &pricingpagesession.CreateForExistingSubscriptionPricingPageParams{
            Id : "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q",
        },
        Subscription : &pricingpagesession.CreateForExistingSubscriptionSubscriptionParams{
            Id : "__test__KyVnHhSBWmCoF2tJ",
        },
    }).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.PricingPageSessionCreateForExistingSubscriptionRequest{
    PricingPage : &chargebee.PricingPageSessionCreateForExistingSubscriptionPricingPage{
        Id : "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q",
    },
    Subscription : &chargebee.PricingPageSessionCreateForExistingSubscriptionSubscription{
        Id : "__test__KyVnHhSBWmCoF2tJ",
    },
}
  res, err := client.PricingPageSession.CreateForExistingSubscription(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.createForExistingSubscription()
            .pricingPageId("01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q")
            .subscriptionId("__test__KyVnHhSBWmCoF2tJ")
            .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.PricingPageSessionCreateForExistingSubscriptionParams;
import com.chargebee.v4.models.pricingPageSession.responses.PricingPageSessionCreateForExistingSubscriptionResponse;

public class PricingPageSessionCreateForExistingSubscription {

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

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

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

        PricingPageSessionCreateForExistingSubscriptionParams params = PricingPageSessionCreateForExistingSubscriptionParams.builder()
            .pricingPage(pricingPageParams)
            .subscription(subscriptionParams)
            .build();

        PricingPageSessionCreateForExistingSubscriptionResponse response = client.pricingPageSessions().createForExistingSubscription(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.createForExistingSubscription({
        pricing_page: {
            id: "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
        },
        subscription: {
            id: "__test__KyVnHhSBWmCoF2tJ"
        }
    });

    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()->createForExistingSubscription([
    "pricing_page" => [
        "id" => "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
    ],
    "subscription" => [
        "id" => "__test__KyVnHhSBWmCoF2tJ"
    ]
]);
$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_existing_subscription(
    cb_client.PricingPageSession.CreateForExistingSubscriptionParams(
        pricing_page=cb_client.PricingPageSession.CreateForExistingSubscriptionPricingPageParams(
            id="01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
        ),
        subscription=cb_client.PricingPageSession.CreateForExistingSubscriptionSubscriptionParams(
            id="__test__KyVnHhSBWmCoF2tJ"
        )
    )
)
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_existing_subscription({
  :pricing_page => {
    :id => "01HTPJN1JKBQ3BQ3ZH7V8X2Z9Q"
  },
  :subscription => {
    :id => "__test__KyVnHhSBWmCoF2tJ"
  }
})

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_existing_subscription

## Input Parameters

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

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

- `subscription` (optional, string)
  Parameters for subscription
  - `id` (required, string, max chars=50)
    The unique identifier of an existing subscription for which the hosted pricing page is created.

- `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` = `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
