# Subscription change term end estimate

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


Generates an estimate for the 'change term end' operation. This is similar to the [Change term end](/docs/api/subscriptions/change-term-end) API but the subscription's term end will not be changed, only an estimate for this operation is created. This is applicable only for subscriptions in 'in-trial', 'active' and 'non-renewing' states.

In the response,

-   **estimate.subscription\_estimate** has the subscription details like the status of the subscription (in\_trial, active, etc.), next billing date, and so on.
-   **estimate.invoice\_estimate** has details of the invoice that will be generated immediately. This will not be present if no immediate invoice is generated for this operation. This will happen when
    -   _prorate_ parameter is false, or
    -   _invoice\_immediately_ parameter is false, or
    -   subscription is in _in-trial_ state
-   **estimate.credit\_note\_estimates\[\]** has details of the credit-notes that will get generated during this operation. This list will be empty if no credit-note gets generated during this operation.
-   **estimate.unbilled\_charge\_estimates\[\]** has details of the unbilled charges. This is returned only if _invoice\_immediately_ is set as false.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__8asyKSOceZF8N6/change_term_end_estimate \
     -u {site_api_key}:\
     -d term_ends_at=1566697500
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Estimate.ChangeTermEnd("__test__8asyKSOceZF8N6")
		.TermEndsAt(1566697500)
		.Request();

Estimate estimate = result.Estimate;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    estimateAction "github.com/chargebee/chargebee-go/v3/actions/estimate"
    "github.com/chargebee/chargebee-go/v3/models/estimate"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := estimateAction.ChangeTermEnd("__test__8asyKSOceZF8N6", &estimate.ChangeTermEndRequestParams{
        TermEndsAt : chargebee.Int64(1566697500),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Estimate := res.Estimate
    }
}
```

#### 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.EstimateChangeTermEndRequest{
    TermEndsAt : chargebee.Int64(1566697500),
}
  res, err := client.Estimate.ChangeTermEnd("__test__8asyKSOceZF8N6", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Estimate := res.Estimate
    }
}
```

#### Java

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

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Estimate.changeTermEnd("__test__8asyKSOceZF8N6")
            .termEndsAt(new Timestamp(1566697500L * 1000))
            .request();

        Estimate estimate = result.estimate();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.estimate.Estimate;
import com.chargebee.v4.models.estimate.params.EstimateChangeTermEndParams;
import com.chargebee.v4.models.estimate.responses.EstimateChangeTermEndResponse;
import java.sql.Timestamp;

public class EstimateChangeTermEnd {

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

        EstimateChangeTermEndParams params = EstimateChangeTermEndParams.builder()
            .termEndsAt(new Timestamp(1566697500L * 1000))
            .build();

        EstimateChangeTermEndResponse response = client
            .estimates()
            .changeTermEnd("__test__8asyKSOceZF8N6", params);

        Estimate estimate = response.getEstimate();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.estimate.changeTermEnd("__test__8asyKSOceZF8N6", {
        term_ends_at: 1566697500
    });

    console.log(result);
    const estimate = result.estimate;
} 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->estimate()->changeTermEnd("__test__8asyKSOceZF8N6", [
    "term_ends_at" => 1566697500
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Estimate.change_term_end("__test__8asyKSOceZF8N6",
    cb_client.Estimate.ChangeTermEndParams(
        term_ends_at=1566697500
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Estimate.change_term_end("__test__8asyKSOceZF8N6",{
  :term_ends_at => 1566697500
})

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1517492954,
    "credit_note_estimates": {},
    "object": "estimate",
    "subscription_estimate": {
      "currency_code": "USD",
      "id": "__test__8asyKSOceZF8N6",
      "next_billing_at": 1566697500,
      "object": "subscription_estimate",
      "status": "active"
    }
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/subscriptions/{subscription-id}/change_term_end_estimate

## Input Parameters

- `term_ends_at` (required, timestamp(UTC) in seconds)
  The time at which the current term should end for this subscription.

- `prorate` (optional, boolean)
  Applicable for _active_ / _non\_renewing_ subscriptions. If specified as _true_ prorated charges / credits will be added during this operation.

- `invoice_immediately` (optional, boolean)
  If there are charges raised immediately for the subscription, this parameter specifies whether those charges are to be invoiced immediately or added to [unbilled charges](https://www.chargebee.com/docs/unbilled-charges.html). The default value is as per the [site settings](https://www.chargebee.com/docs/unbilled-charges.html#configuration) .
  
  **Note:** `invoice_immediately` only affects charges that are raised at the time of execution of this API call. Any charges scheduled to be raised in the future are not affected by this parameter.
  
  .

## Returns

- `estimate` (Estimate object)
  Resource object representing estimate
