# Extend subscription

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


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

This API generates a hosted page URL to extend the billing cycle of a subscription.

Use one of the following methods to open the hosted page:

-   **In-app modal**: Use Chargebee.js [`openCheckout()`](https://www.chargebee.com/checkout-portal-docs/cbinstanceobj-api-ref.html#opencheckout-options) to open the hosted page in a modal popup in your website or application.
-   **Standalone page**: Redirect the customer to the hosted page `url`.

Do not embed the hosted page in your own [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/iframe).

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/hosted_pages/extend_subscription \
     -u {site_api_key}:\
     -d "subscription[id]"="__test__KyVnHhSBWmIgw2u6" \
     -d billing_cycle=2 \
     -d expiry=14
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = HostedPage.ExtendSubscription()
		.SubscriptionId("__test__KyVnHhSBWmIgw2u6")
		.BillingCycle(2)
		.Expiry(14)
		.Request();

HostedPage hostedPage = result.HostedPage;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    hostedpageAction "github.com/chargebee/chargebee-go/v3/actions/hostedpage"
    "github.com/chargebee/chargebee-go/v3/models/hostedpage"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := hostedpageAction.ExtendSubscription(&hostedpage.ExtendSubscriptionRequestParams{
        Subscription : &hostedpage.ExtendSubscriptionSubscriptionParams{
            Id : "__test__KyVnHhSBWmIgw2u6",
        },
        BillingCycle : chargebee.Int32(2),
        Expiry : chargebee.Int32(14),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        HostedPage := res.HostedPage
    }
}
```

#### 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.HostedPageExtendSubscriptionRequest{
    Subscription : &chargebee.HostedPageExtendSubscriptionSubscription{
        Id : "__test__KyVnHhSBWmIgw2u6",
    },
    BillingCycle : chargebee.Int32(2),
    Expiry : chargebee.Int32(14),
}
  res, err := client.HostedPage.ExtendSubscription(req)
      if err != nil {
        fmt.Println(err)
    } else {
        HostedPage := res.HostedPage
    }
}
```

#### 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 = HostedPage.extendSubscription()
            .subscriptionId("__test__KyVnHhSBWmIgw2u6")
            .billingCycle(2)
            .expiry(14)
            .request();

        HostedPage hostedPage = result.hostedPage();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.hostedPage.HostedPage;
import com.chargebee.v4.models.hostedPage.params.HostedPageExtendSubscriptionParams;
import com.chargebee.v4.models.hostedPage.responses.HostedPageExtendSubscriptionResponse;

public class HostedPageExtendSubscription {

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

        HostedPageExtendSubscriptionParams.SubscriptionParams subscriptionParams =
            HostedPageExtendSubscriptionParams.SubscriptionParams.builder()
                .id("__test__KyVnHhSBWmIgw2u6")
                .build();

        HostedPageExtendSubscriptionParams params = HostedPageExtendSubscriptionParams.builder()
            .subscription(subscriptionParams)
            .billingCycle(2)
            .expiry(14)
            .build();

        HostedPageExtendSubscriptionResponse response = client.hostedPages().extendSubscription(params);

        HostedPage hostedPage = response.getHostedPage();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.hostedPage.extendSubscription({
        subscription: {
            id: "__test__KyVnHhSBWmIgw2u6"
        },
        billing_cycle: 2,
        expiry: 14
    });

    console.log(result);
    const hostedPage = result.hosted_page;
} 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->hostedPage()->extendSubscription([
    "subscription" => [
        "id" => "__test__KyVnHhSBWmIgw2u6"
    ],
    "billing_cycle" => 2,
    "expiry" => 14
]);
$hostedPage = $result->hosted_page;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.HostedPage.extend_subscription(
    cb_client.HostedPage.ExtendSubscriptionParams(
        subscription=cb_client.HostedPage.ExtendSubscriptionSubscriptionParams(
            id="__test__KyVnHhSBWmIgw2u6"
        ),
        billing_cycle=2,
        expiry=14
    )
)
hosted_page = response.hosted_page
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::HostedPage.extend_subscription({
  :subscription => {
    :id => "__test__KyVnHhSBWmIgw2u6"
  },
  :billing_cycle => 2,
  :expiry => 14
})

hosted_page = result.hosted_page
```

## Sample Response

```json
{
  "hosted_page": {
    "created_at": 1517506012,
    "embed": true,
    "expires_at": 1518715612,
    "id": "__test__Bct8ySC6A1eV2GdMcdUl7dzovgyKhAz4M",
    "object": "hosted_page",
    "resource_version": 1517506012000,
    "state": "created",
    "type": "extend_subscription",
    "updated_at": 1517506012,
    "url": "https://yourapp.chargebee.com/pages/v3/__test__Bct8ySC6A1eV2GdMcdUl7dzovgyKhAz4M/"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/hosted_pages/extend_subscription

## Input Parameters

- `brand_id` (optional, string, max chars=50)
  The unique ID of the [brand](/docs/api/brands) this hosted page should be linked to. Applicable only when multiple brands have been created for the site. This need not match the brand of the customer or subscription in the request; when the two differ, the value provided here is used for the hosted page. 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 hosted page is linked to the brand of the customer or subscription in the request.

- `expiry` (optional, integer, min=1, max=500)
  Expiry (in days) for the link generated. No expiry will be set if this is not specified.

- `billing_cycle` (optional, integer, min=1)
  The number of billing cycles by which the subscription should be extended.
  
  **Default behavior**
  
  -   If the subscription's plan has [`billing_cycles`](/docs/api/item_prices#billing_cycles) set, that value is used.
  -   If the plan's billing cycles attribute is not set, `1` is used.

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

## Returns

- `hosted_page` (Hosted page object)
  Resource object representing hosted\_page
