# Create subscription for a customer estimate

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


Create a subscription for the existing estimate of a customer.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__KyVnHhSBWl2XD2aV/create_subscription_estimate \
     -G  \
     -u {site_api_key}:\
     -d "subscription[plan_id]"="no_trial"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Estimate.CreateSubForCustomerEstimate("__test__KyVnHhSBWl2XD2aV")
		.SubscriptionPlanId("no_trial")
		.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.CreateSubForCustomerEstimate("__test__KyVnHhSBWl2XD2aV", &estimate.CreateSubForCustomerEstimateRequestParams{
        Subscription : &estimate.CreateSubForCustomerEstimateSubscriptionParams{
            PlanId : "no_trial",
        },
    }).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.EstimateCreateSubForCustomerEstimateRequest{
    Subscription : &chargebee.EstimateCreateSubForCustomerEstimateSubscription{
        PlanId : "no_trial",
    },
}
  res, err := client.Estimate.CreateSubForCustomerEstimate("__test__KyVnHhSBWl2XD2aV", 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;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Estimate.createSubForCustomerEstimate("__test__KyVnHhSBWl2XD2aV")
            .subscriptionPlanId("no_trial")
            .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.CreateSubscriptionForCustomerEstimateParams;
import com.chargebee.v4.models.estimate.responses.CreateSubscriptionForCustomerEstimateResponse;

public class CreateSubscriptionForCustomerEstimate {

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

        CreateSubscriptionForCustomerEstimateParams.SubscriptionParams subscriptionParams =
            CreateSubscriptionForCustomerEstimateParams.SubscriptionParams.builder()
                .planId("no_trial")
                .build();

        CreateSubscriptionForCustomerEstimateParams params = CreateSubscriptionForCustomerEstimateParams.builder()
            .subscription(subscriptionParams)
            .build();

        CreateSubscriptionForCustomerEstimateResponse response = client
            .estimates()
            .createSubscriptionForCustomerEstimate("__test__KyVnHhSBWl2XD2aV", 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.createSubForCustomerEstimate("__test__KyVnHhSBWl2XD2aV", {
        subscription: {
            plan_id: "no_trial"
        }
    });

    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()->createSubForCustomerEstimate("__test__KyVnHhSBWl2XD2aV", [
    "subscription" => [
        "plan_id" => "no_trial"
    ]
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Estimate.create_sub_for_customer_estimate("__test__KyVnHhSBWl2XD2aV",
    cb_client.Estimate.CreateSubForCustomerEstimateParams(
        subscription=cb_client.Estimate.CreateSubForCustomerEstimateSubscriptionParams(
            plan_id="no_trial"
        )
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Estimate.create_sub_for_customer_estimate("__test__KyVnHhSBWl2XD2aV",{
  :subscription => {
    :plan_id => "no_trial"
  }
})

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1517505711,
    "invoice_estimate": {
      "amount_due": 895,
      "amount_paid": 0,
      "credits_applied": 0,
      "currency_code": "USD",
      "customer_id": "__test__KyVnHhSBWl2XD2aV",
      "date": 1517505711,
      "line_item_discounts": {},
      "line_item_taxes": {},
      "line_items": [
        {
          "amount": 895,
          "customer_id": "__test__KyVnHhSBWl2XD2aV",
          "date_from": 1517505711,
          "date_to": 1519924911,
          "description": "No Trial",
          "discount_amount": 0,
          "entity_id": "no_trial",
          "entity_type": "plan",
          "id": "li___test__KyVnHhSBWl2Yy2aZ",
          "is_taxed": false,
          "item_level_discount_amount": 0,
          "object": "line_item",
          "pricing_model": "per_unit",
          "quantity": 1,
          "tax_amount": 0,
          "unit_amount": 895
        },
        {..}
      ],
      "object": "invoice_estimate",
      "price_type": "tax_exclusive",
      "recurring": true,
      "round_off_amount": 0,
      "sub_total": 895,
      "taxes": {},
      "total": 895
    },
    "object": "estimate",
    "subscription_estimate": {
      "currency_code": "USD",
      "next_billing_at": 1519924911,
      "object": "subscription_estimate",
      "status": "active"
    }
  }
}
```

## URL Format

**GET** https://[site].chargebee.com/api/v2/customers/{customer-id}/create_subscription_estimate

## Input Parameters

- `use_existing_balances` (optional, boolean, default=true)
  The generated invoice\_estimate/next\_invoice\_estimate will include all the balances - Promotional Credits, Refundable Credits, and Excess Payments - if any. If you don't want these balances to be included you can specify 'false' for the parameter _use\_existing\_balances_ .

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

- `billing_cycles` (optional, integer, min=0)
  Number of cycles(plan interval) this subscription should be charged. After the billing cycles exhausted, the subscription will be cancelled.

- `mandatory_addons_to_remove` (optional, array)
  List of addons IDs that are mandatory to the plan and has to be removed from the subscription.

- `terms_to_charge` (optional, integer, min=1)
  The number of subscription billing cycles (including the first one) to [invoice in advance](https://www.chargebee.com/docs/advance-invoices.html) .

- `billing_alignment_mode` (optional, enumerated string)
  Override the [billing alignment mode](https://www.chargebee.com/docs/calendar-billing.html#alignment-of-billing-date) for Calendar Billing. Only applicable when using Calendar Billing. The default value is that which has been configured for the site.
  Possible enum values:
    - `immediate`
    - `delayed`

- `invoice_date` (optional, timestamp(UTC) in seconds)
  The document date displayed on the invoice PDF. By default, it is the date of creation of the invoice or, when Metered Billing is enabled, it can be the date of closing the invoice. Provide this value to backdate the invoice (set the invoice date to a value in the past). Backdating an invoice is done for reasons such as booking revenue for a previous date or when the non-recurring charge is effective as of a past date. `taxes` and `line_item_taxes` are computed based on the tax configuration as of this date. The date should not be more than one calendar month into the past. For example, if today is 13th January, then you cannot pass a value that is earlier than 13th December.

- `coupon_ids` (optional, array)
  List of coupons to be applied to this subscription. You can provide coupon ids or coupon codes.

- `subscription` (optional, object)
  Parameters for subscription

- `shipping_address` (optional, object)
  Parameters for shipping\_address

- `contract_term` (optional, object)
  Parameters for contract\_term

- `addons` (optional, object)
  Parameters for addons

- `event_based_addons` (optional, object)
  Parameters for event\_based\_addons

## Returns

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