# Change term end

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


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

Use this endpoint to adjust when a subscription's current term or trial ends without altering the plan or billing frequency. It is helpful when you need to align renewals to a specific calendar date or extend a trial. Future renewals will follow the new date, keeping the subscription cadence intact.

### Prerequisites & Constraints

Subscriptions must be in one of the following [`status`](/docs/api/subscriptions/subscription-object#status) values: `in_trial`, `active`, `non_renewing`.

### Impacts

**

Subscription

**

Based on the subscription's `status`, the following updates are made:

-   If the status is `in_trial`, the `trial_end` is set to the new date.
-   If the status is `active`, the `current_term_end` is set to the new date.
-   If the status is `non_renewing`, the upcoming cancellation date is set to the new date.

**

Invoices and Credit Notes

**

The API can generate unbilled charges, invoice, or credit notes. You can control the behaviour using `prorate` and `invoice_immediately` parameters. To preview invoices, credits, and dates, use the [Change term end estimate](/docs/api/estimates/subscription-change-term-end-estimate) endpoint.

**

Advance Charges

**

If there are advance charges, then credit notes are issued for the unused portion of the service period.

**

Scheduled Pause

**

If the subscription is **scheduled** to **pause** at the end of the current term, the pause date is updated to match the new term end date.

**

Ramps

**

If [subscription ramps](/docs/api/ramps) are present, this operation moves them to the `draft` state. Update and reschedule the ramps as needed to keep them in sync.

### Implementation Notes

The request fails with `invalid_state` if the subscription is **not** in one of the `trial`, `active`, or `non_renewing` states. Validate the status before invoking this API.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__8asukSOXdtByMK/change_term_end \
     -u {site_api_key}:\
     -d term_ends_at=1745951400
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.ChangeTermEnd("__test__8asukSOXdtByMK")
		.TermEndsAt(1745951400)
		.Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
Invoice invoice = result.Invoice;
List<UnbilledCharge> unbilledCharges = result.UnbilledCharges;
List<CreditNote> creditNotes = result.CreditNotes;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    subscriptionAction "github.com/chargebee/chargebee-go/v3/actions/subscription"
    "github.com/chargebee/chargebee-go/v3/models/subscription"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := subscriptionAction.ChangeTermEnd("__test__8asukSOXdtByMK", &subscription.ChangeTermEndRequestParams{
        TermEndsAt : chargebee.Int64(1745951400),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### 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.SubscriptionChangeTermEndRequest{
    TermEndsAt : chargebee.Int64(1745951400),
}
  res, err := client.Subscription.ChangeTermEnd("__test__8asukSOXdtByMK", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### Java

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

public class Sample {

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

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
        Invoice invoice = result.invoice();
        List<UnbilledCharge> unbilledCharges = result.unbilledCharges();
        List<CreditNote> creditNotes = result.creditNotes();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.subscription.params.SubscriptionChangeTermEndParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionChangeTermEndResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.sql.Timestamp;
import java.util.List;

public class SubscriptionChangeTermEnd {

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

        SubscriptionChangeTermEndParams params = SubscriptionChangeTermEndParams.builder()
            .termEndsAt(new Timestamp(1745951400L * 1000))
            .build();

        SubscriptionChangeTermEndResponse response = client
            .subscriptions()
            .changeTermEnd("__test__8asukSOXdtByMK", params);

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
        Invoice invoice = response.getInvoice();
        List<UnbilledCharge> unbilledCharges = response.getUnbilledCharges();
        List<CreditNote> creditNotes = response.getCreditNotes();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.changeTermEnd("__test__8asukSOXdtByMK", {
        term_ends_at: 1745951400
    });

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
    const invoice = result.invoice;
    const unbilledCharges = result.unbilled_charges;
    const creditNotes = result.credit_notes;
} 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->subscription()->changeTermEnd("__test__8asukSOXdtByMK", [
    "term_ends_at" => 1745951400
]);
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
$invoice = $result->invoice;
$unbilledCharges = $result->unbilled_charges;
$creditNotes = $result->credit_notes;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.change_term_end("__test__8asukSOXdtByMK",
    cb_client.Subscription.ChangeTermEndParams(
        term_ends_at=1745951400
    )
)
subscription = response.subscription
customer = response.customer
card = response.card
invoice = response.invoice
unbilled_charges = response.unbilled_charges
credit_notes = response.credit_notes
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.change_term_end("__test__8asukSOXdtByMK",{
  :term_ends_at => 1745951400
})

subscription = result.subscription
customer = result.customer
card = result.card
invoice = result.invoice
unbilled_charges = result.unbilled_charges
credit_notes = result.credit_notes
```

## Sample Response

```json
{
  "subscription": {
    "id": "16BPffUgMfxc58aJ",
    "billing_period": 1,
    "billing_period_unit": "month",
    "customer_id": "Azq8jIUfp36JT91T",
    "status": "active",
    "current_term_start": 1742754600,
    "current_term_end": 1745951399,
    "next_billing_at": 1745951400,
    "created_at": 1742819726,
    "started_at": 1742754600,
    "activated_at": 1742754600,
    "updated_at": 1742819811,
    "has_scheduled_changes": false,
    "channel": "web",
    "resource_version": 1742819811819,
    "deleted": false,
    "object": "subscription",
    "currency_code": "USD",
    "subscription_items": [
      {
        "item_price_id": "elle-826",
        "item_type": "plan",
        "quantity": 1,
        "quantity_in_decimal": "1.0000",
        "unit_price": 2300,
        "unit_price_in_decimal": "23.00000",
        "amount": 2300,
        "amount_in_decimal": "23.00000",
        "free_quantity": 0,
        "free_quantity_in_decimal": "0.0000",
        "object": "subscription_item"
      },
      {..}
    ],
    "due_invoices_count": 1,
    "due_since": 1742754600,
    "total_dues": 2300,
    "mrr": 2300,
    "exchange_rate": 1,
    "base_currency_code": "USD",
    "has_scheduled_advance_invoices": false,
    "override_relationship": false,
    "create_pending_invoices": false,
    "auto_close_invoices": true
  },
  "customer": {
    "id": "Azq8jIUfp36JT91T",
    "first_name": "Erika",
    "last_name": "Mustermann",
    "auto_collection": "off",
    "net_term_days": 0,
    "allow_direct_debit": false,
    "created_at": 1742322846,
    "taxability": "taxable",
    "updated_at": 1742819695,
    "pii_cleared": "active",
    "channel": "web",
    "resource_version": 1742819695354,
    "deleted": false,
    "object": "customer",
    "card_status": "no_card",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "excess_payments": 0,
    "unbilled_charges": 0,
    "preferred_currency_code": "USD",
    "mrr": 4800,
    "auto_close_invoices": true
  }
}
```

## URL Format

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

## Input Parameters

- `term_ends_at` (required, timestamp(UTC) in seconds)
  The time at which the current term should end for this subscription. The value must be a date in the future, i.e. later than current time. The value must not be the same as `[next_billing_at](/docs/api/subscriptions/subscription-object#next_billing_at)` .

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

- `subscription` (Subscription object)
  Resource object representing subscription

- `customer` (Customer object)
  Resource object representing customer

- `card` (Card object)
  Resource object representing card

- `invoice` (Invoice object)
  Resource object representing invoice

- `unbilled_charges` (optional)
  Resource object representing unbilled\_charge

- `credit_notes` (optional)
  Resource object representing credit\_note
