# Create a pre-cancel hosted page

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


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

Creates a `hosted_page` resource of `type` `pre_cancel` . Route canceling users to this page to provide them a retention experience and start saving revenue. The hosted page is created in accordance with the retention experience [configured in the Chargebee Growth app](https://www.chargebee.com/docs/growth/experiences/setting-up-cancel-pages) , along with the data provided as input to this endpoint. Call the endpoint before your customer clicks the **Cancel** button, and when they do, route them to the `[url](/docs/api/hosted_pages/hosted_page-object#url)` in the endpoint response.

## Sample Request

#### Chargebee CLI

```bash
chargebee hosted-page pre-cancel \
    -d 'subscription[id]=__test__KyVnHhSBWmCoF2tJ' \
    -d 'pass_thru_content={custom :  {discount_percent: 10}}'
```

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/hosted_pages/pre_cancel \
     -u {site_api_key}:\
     -d "subscription[id]"="__test__KyVnHhSBWmCoF2tJ" \
     -d pass_thru_content='{custom :  {discount_percent: 10}}'
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = HostedPage.PreCancel()
		.SubscriptionId("__test__KyVnHhSBWmCoF2tJ")
		.PassThruContent("{custom :  {discount_percent: 10}}")
		.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.PreCancel(&hostedpage.PreCancelRequestParams{
        Subscription : &hostedpage.PreCancelSubscriptionParams{
            Id : "__test__KyVnHhSBWmCoF2tJ",
        },
        PassThruContent : "{custom :  {discount_percent: 10}}",
    }).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.HostedPagePreCancelRequest{
    Subscription : &chargebee.HostedPagePreCancelSubscription{
        Id : "__test__KyVnHhSBWmCoF2tJ",
    },
    PassThruContent : "{custom :  {discount_percent: 10}}",
}
  res, err := client.HostedPage.PreCancel(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.preCancel()
            .subscriptionId("__test__KyVnHhSBWmCoF2tJ")
            .passThruContent("{custom :  {discount_percent: 10}}")
            .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.HostedPagePreCancelParams;
import com.chargebee.v4.models.hostedPage.responses.HostedPagePreCancelResponse;

public class HostedPagePreCancel {

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

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

        HostedPagePreCancelParams params = HostedPagePreCancelParams.builder()
            .subscription(subscriptionParams)
            .passThruContent("{custom :  {discount_percent: 10}}")
            .build();

        HostedPagePreCancelResponse response = client.hostedPages().preCancel(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.preCancel({
        subscription: {
            id: "__test__KyVnHhSBWmCoF2tJ"
        },
        pass_thru_content: "{custom :  {discount_percent: 10}}"
    });

    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()->preCancel([
    "subscription" => [
        "id" => "__test__KyVnHhSBWmCoF2tJ"
    ],
    "pass_thru_content" => "{custom :  {discount_percent: 10}}"
]);
$hostedPage = $result->hosted_page;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.HostedPage.pre_cancel(
    cb_client.HostedPage.PreCancelParams(
        subscription=cb_client.HostedPage.PreCancelSubscriptionParams(
            id="__test__KyVnHhSBWmCoF2tJ"
        ),
        pass_thru_content='{custom :  {discount_percent: 10}}'
    )
)
hosted_page = response.hosted_page
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::HostedPage.pre_cancel({
  :subscription => {
    :id => "__test__KyVnHhSBWmCoF2tJ"
  },
  :pass_thru_content => "{custom :  {discount_percent: 10}}"
})

hosted_page = result.hosted_page
```

## Sample Response

```json
{
  "hosted_page": {
    "id": "__dev__uxMMdSCbO8zweGryJDU37zfbdGxC3Gn9",
    "type": "pre_cancel",
    "url": "https://app.brightback.com/session/mVS0ecj6tswr3Ss",
    "state": "created",
    "pass_thru_content": "{custom :  {discount_percentage: 10}}",
    "created_at": 1653382696,
    "expires_at": 1653386296,
    "content": {},
    "object": "hosted_page"
  }
}
```

## URL Format

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

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

- `pass_thru_content` (optional, string, max chars=2048)
  Additional data to be passed to Chargebee Growth. Only the value of `pass_thru_content.custom` is sent to Chargebee Growth. It is sent as the value of the [`custom`](https://www.chargebee.com/docs/js/cancel-page-api-ref#parameters) property. The fields provided in `pass_thru_content.custom` must be preconfigured in Chargebee Growth.
  
  Although only `pass_thru_content.custom` is sent to Chargebee Growth, all of `pass_thru_content` is stored by Chargebee Billing and is retrievable as an [attribute](/docs/api/hosted_pages/hosted_page-object#pass_thru_content) of the `hosted_page`. .

- `cancel_url` (optional, string, max chars=250)
  The customer is sent to this URL if they finally decide to cancel the subscription, despite the attempt to retain them.

- `redirect_url` (optional, string, max chars=250)
  The customer is sent to this URL upon successful retention. In other words, this is the page to which the customer is sent when they decide **not** to cancel the subscription.

- `locale` (optional, string, max chars=50)

- `subscription` (optional, string)
  Parameters for subscription
  - `id` (required, string, max chars=50)
    The unique ID of the subscription which the customer wants to cancel.

## Returns

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