# Delete a subscription

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


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

Deletes a specified subscription.

This operation schedules the subscription resource for deletion, and it is **permanently** deleted after a few minutes. If you wish to retain the subscription data but stop further renewals, consider [canceling](/docs/api/subscriptions/cancel-subscription-for-items) or [pausing](/docs/api/subscriptions/pause-a-subscription) the subscription instead.

### Prerequisites & Constraints

-   There must not be any [invoices](/docs/api/invoices) belonging to this subscription that have allocations from [credit notes](/docs/api/credit_notes) **not** belonging to this subscription.
-   There must not be any credit notes belonging to this subscription that have been allocated to invoices **not** belonging to this subscription.
-   There should not be any consolidated invoices for the [customer](/docs/api/customers) with lines belonging to this subscription.

### Impacts

**

Invoices

**

-   All the invoices belonging to the subscription are deleted.
-   See [Delete an invoice API](/docs/api/invoices/delete-an-invoice) for more details on the impacts of deleting an invoice.

**

Credit notes

**

All the credit notes belonging to this subscription are deleted.

**

Transactions

**

All the [transactions](/docs/api/transactions) belonging to this subscription are deleted.

**

Usages

**

All [usages](/docs/api/usages) belonging to this subscription are deleted.

**

Usage events

**

Deleting a subscription does **not** delete the associated [usage events](/docs/api/usage_events).

**

Reporting

**

The numbers in the following [reports](https://www.chargebee.com/docs/billing/2.0/reports-and-analytics/metric_description) are modified when a subscription is deleted: Payments, New Revenue, Signups, Activations, Cancellations, and Refunds.

**

Integrations

**

Deleting a subscription may affect any [third-party integrations](https://www.chargebee.com/docs/billing/2.0/integrations/sales-integration-index) you may have with Chargebee Billing. Review all integrations to assess the impact before proceeding.

### Implementation Notes

Before deleting a subscription, ensure the following:

-   Retrieve all the invoices for this subscription using the [List invoices API](/docs/api/invoices/list-invoices). For each invoice, look up all the applied credit notes (`credit_note.applied_credits.cn_id`). For all such credit notes, check if the associated subscription (`credit_note.subscription_id`) is this subscription. If not, use the [Remove credit note from an invoice API](/docs/api/invoices/remove-credit-note-from-an-invoice) to remove the credit note allocation.
-   Retrieve all the credit notes for this subscription using the [List credit notes API](/docs/api/credit_notes/list-credit-notes). For each credit note, look up all the invoice allocations (`credit_note.allocations.invoice_id`). For all such invoices, check if the associated subscription (`invoice.subscription_id`) is this subscription. If not, use the [Remove credit note from an invoice API](/docs/api/invoices/remove-credit-note-from-an-invoice) to remove the allocation.
-   [Delete](/docs/api/invoices/delete-an-invoice) any consolidated invoices containing lines belonging to this subscription.

#### Related APIs

Pause a subscription

Cancel a subscription

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__8asukSOXdv6kOj/delete \
     -X POST  \
     -u {site_api_key}:
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.Delete("__test__8asukSOXdv6kOj").Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    subscriptionAction "github.com/chargebee/chargebee-go/v3/actions/subscription"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := subscriptionAction.Delete("__test__8asukSOXdv6kOj").Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
    }
}
```

#### 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)
  
  res, err := client.Subscription.Delete("__test__8asukSOXdv6kOj")
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
    }
}
```

#### 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 = Subscription.delete("__test__8asukSOXdv6kOj").request();

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.subscription.params.SubscriptionDeleteParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionDeleteResponse;

public class SubscriptionDelete {

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

        SubscriptionDeleteResponse response = client.subscriptions().delete("__test__8asukSOXdv6kOj");

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.delete("__test__8asukSOXdv6kOj");

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
} 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()->delete("__test__8asukSOXdv6kOj");
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.delete("__test__8asukSOXdv6kOj")
subscription = response.subscription
customer = response.customer
card = response.card
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.delete("__test__8asukSOXdv6kOj")

subscription = result.subscription
customer = result.customer
card = result.card
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "off",
    "card_status": "no_card",
    "created_at": 1612890917,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "John",
    "id": "__test__8asukSOXdv0dOg",
    "last_name": "Doe",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1612890917000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1612890917
  },
  "subscription": {
    "activated_at": 1612890917,
    "billing_period": 1,
    "billing_period_unit": "month",
    "created_at": 1612890917,
    "currency_code": "USD",
    "current_term_end": 1615310117,
    "current_term_start": 1612890917,
    "customer_id": "__test__8asukSOXdv0dOg",
    "deleted": false,
    "due_invoices_count": 1,
    "due_since": 1612890917,
    "has_scheduled_changes": false,
    "id": "__test__8asukSOXdv6kOj",
    "mrr": 0,
    "next_billing_at": 1615310117,
    "object": "subscription",
    "remaining_billing_cycles": 1,
    "resource_version": 1612890918000,
    "started_at": 1612890917,
    "status": "active",
    "subscription_items": [
      {
        "amount": 1000,
        "billing_cycles": 1,
        "free_quantity": 0,
        "item_price_id": "basic-USD",
        "item_type": "plan",
        "object": "subscription_item",
        "quantity": 1,
        "unit_price": 1000
      },
      {..}
    ],
    "total_dues": 1100,
    "updated_at": 1612890918
  }
}
```

## URL Format

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

## Returns

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

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

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