# Advance invoice estimate

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


This API is used to generate an invoice estimate for preview. Estimate details include the number of billing cycles to be invoiced in advance, the number of billing cycles in one interval, advance invoicing schedules, and so on.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__KyVkjcSAl6gBw1/advance_invoice_estimate \
     -u {site_api_key}:\
     -d invoice_immediately="false" \
     -d terms_to_charge=3
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Estimate.AdvanceInvoiceEstimate("__test__KyVkjcSAl6gBw1")
		.InvoiceImmediately(false)
		.TermsToCharge(3)
		.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.AdvanceInvoiceEstimate("__test__KyVkjcSAl6gBw1", &estimate.AdvanceInvoiceEstimateRequestParams{
        InvoiceImmediately : chargebee.Bool(false),
        TermsToCharge : chargebee.Int32(3),
    }).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.EstimateAdvanceInvoiceEstimateRequest{
    InvoiceImmediately : chargebee.Bool(false),
    TermsToCharge : chargebee.Int32(3),
}
  res, err := client.Estimate.AdvanceInvoiceEstimate("__test__KyVkjcSAl6gBw1", 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.advanceInvoiceEstimate("__test__KyVkjcSAl6gBw1")
            .invoiceImmediately(false)
            .termsToCharge(3)
            .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.AdvanceInvoiceEstimateParams;
import com.chargebee.v4.models.estimate.responses.AdvanceInvoiceEstimateResponse;

public class AdvanceInvoiceEstimate {

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

        AdvanceInvoiceEstimateParams params = AdvanceInvoiceEstimateParams.builder()
            .invoiceImmediately(false)
            .termsToCharge(3)
            .build();

        AdvanceInvoiceEstimateResponse response = client
            .estimates()
            .advanceInvoiceEstimate("__test__KyVkjcSAl6gBw1", 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.advanceInvoiceEstimate("__test__KyVkjcSAl6gBw1", {
        invoice_immediately: false,
        terms_to_charge: 3
    });

    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()->advanceInvoiceEstimate("__test__KyVkjcSAl6gBw1", [
    "invoice_immediately" => false,
    "terms_to_charge" => 3
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Estimate.advance_invoice_estimate("__test__KyVkjcSAl6gBw1",
    cb_client.Estimate.AdvanceInvoiceEstimateParams(
        invoice_immediately=False,
        terms_to_charge=3
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Estimate.advance_invoice_estimate("__test__KyVkjcSAl6gBw1",{
  :invoice_immediately => "false",
  :terms_to_charge => 3
})

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1517492806,
    "object": "estimate",
    "unbilled_charge_estimates": [
      {
        "amount": 895,
        "currency_code": "USD",
        "customer_id": "__test__KyVkjcSAl6gBw1",
        "date_from": 1519912004,
        "date_to": 1522590404,
        "deleted": false,
        "description": "No Trial",
        "discount_amount": 0,
        "entity_id": "no_trial",
        "entity_type": "plan",
        "id": "li___test__KyVkjcSAl6gcKF",
        "is_voided": false,
        "object": "unbilled_charge",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__KyVkjcSAl6gBw1",
        "unit_amount": 895
      },
      {..}
    ]
  }
}
```

## URL Format

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

## Input Parameters

- `terms_to_charge` (optional, integer, default=1, min=1)
  -   For `schedule_type = immediate`: the number of future billing cycles to be invoiced in advance. The invoicing is done for the [`remaining_billing_cycles`](/docs/api/subscriptions/subscription-object#remaining_billing_cycles) of the subscription if that is less than `terms_to_charge`.
  -   For `schedule_type = fixed_intervals`: The number of future billing cycles in one [interval](/docs/api/advance_invoice_schedules). The schedule is created such that the total number of billing cycles in the schedule does not exceed the [remaining\_billing\_cycles](/docs/api/subscriptions/subscription-object#remaining_billing_cycles) of the subscription. .

- `invoice_immediately` (optional, boolean)
  Whether the charge should be invoiced immediately or added to [`unbilled_charges`](/docs/api/unbilled_charges). Applicable only when [`schedule_type`](/docs/api/subscriptions/charge-future-renewals#schedule_type) is `immediate` .

- `schedule_type` (optional, enumerated string)
  The type of advance invoice or advance invoicing schedule.
  Possible enum values:
    - `immediate`
      Charge immediately for the number of billing cycles specified by [`terms_to_charge`](/docs/api/subscriptions/charge-future-renewals#terms_to_charge) .
    - `specific_dates`
      Charge on [specific dates](/docs/api/subscriptions/charge-future-renewals#specific_dates_schedule_date). For each date, specify the [number of billing cycles](/docs/api/subscriptions/charge-future-renewals#specific_dates_schedule_terms_to_charge) to charge for. Up to 5 dates can be configured.
    - `fixed_intervals`
      Charge at fixed intervals of time. Specify the [number of billing cycles](/docs/api/subscriptions/charge-future-renewals#terms_to_charge) that constitute an interval and the number of [days before each interval](/docs/api/subscriptions/charge-future-renewals#fixed_interval_schedule_days_before_renewal) that the invoice should be generated. Also specify [when the schedule should end](/docs/api/subscriptions/charge-future-renewals#fixed_interval_schedule_end_schedule_on) .

- `fixed_interval_schedule` (optional, integer)
  Parameters for fixed\_interval\_schedule
  - `number_of_occurrences` (optional, integer, min=1)
    The number of advance invoices to generate. The schedule is created such that the total number of billing cycles in the schedule does not exceed the [`remaining_billing_cycles`](/docs/api/subscriptions/subscription-object#remaining_billing_cycles) of the subscription. This parameter is applicable only when [`fixed_interval_schedule[end_schedule_on]`](/docs/api/advance_invoice_schedules/advance_invoice_schedule-object#fixed_interval_schedule_end_schedule_on) = `after_number_of_intervals`
  - `days_before_renewal` (optional, integer, min=1)
    The number of days before each interval that advance invoices are generated.
  - `end_schedule_on` (optional, enumerated string)
    Specifies when the schedule should end.
    Possible enum values:
      - `after_number_of_intervals`
        Advance invoices are generated a `specified number of times`
      - `specific_date`
        End the advance invoicing schedule on a `specific date` .
      - `subscription_end`
        Advance invoices are generated for as long as the subscription is active.
  - `end_date` (optional, timestamp(UTC) in seconds)
    The date when the schedule should end. Advance invoices are not generated beyond this date. It must be at least 1 day before the start of the last billing cycle of the subscription and also within 5 years from the current date. This parameter is only applicable when [`fixed_interval_schedule[end_schedule_on]`](/docs/api/advance_invoice_schedules/advance_invoice_schedule-object#fixed_interval_schedule_end_schedule_on) = `specific_date` .

- `specific_dates_schedule` (optional, array)
  Parameters for specific\_dates\_schedule
  - `terms_to_charge` (optional, integer)
    The number of billing cycles to charge for, on the date specified. Applicable only when [`schedule_type`](/docs/api/advance_invoice_schedules/advance_invoice_schedule-object#schedule_type) is specific\_dates.
  - `date` (optional, timestamp(UTC) in seconds)
    The unique id of the member of the advance\_invoice\_schedule array which corresponds to the specific\_dates\_schedule that you intend to modify. Only applicable when [`schedule_type`](/docs/api/advance_invoice_schedules/advance_invoice_schedule-object#schedule_type) is `specific_dates` .

## Returns

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