# Regenerate invoice estimate

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


Regenerates the invoice for the current term of the subscription. The subscription must have `status` as `active` or `non_renewing`. This operation is not allowed when any of the following conditions hold true for the subscription:

-   An invoice exists for the current term and its `status` is not `voided`.
-   There are [unbilled charges](https://www.chargebee.com/docs/unbilled-charges.html) for the current term.
-   The subscription has an [advance invoice](https://www.chargebee.com/docs/advance-invoices.html).

#### Response[](#response)

Returns an `estimate` object with one of the following components depending on the value of `invoice_immediately`.

-   If the value is `true`: an `invoice_estimate` object that corresponds to the regenerated invoice.
-   If the value is `false`: a list of `unbilled_charge_estimate` objects corresponding to all the unbilled charges created for the current term of the subscription.

## Sample Request

### Default

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__KyVnOuSHufvfo16/regenerate_invoice_estimate \
     -u {site_api_key}:\
     -d invoice_immediately="true"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Estimate.RegenerateInvoiceEstimate("__test__KyVnOuSHufvfo16")
		.InvoiceImmediately(true)
		.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.RegenerateInvoiceEstimate("__test__KyVnOuSHufvfo16", &estimate.RegenerateInvoiceEstimateRequestParams{
        InvoiceImmediately : chargebee.Bool(true),
    }).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.EstimateRegenerateInvoiceEstimateRequest{
    InvoiceImmediately : chargebee.Bool(true),
}
  res, err := client.Estimate.RegenerateInvoiceEstimate("__test__KyVnOuSHufvfo16", 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.regenerateInvoiceEstimate("__test__KyVnOuSHufvfo16")
            .invoiceImmediately(true)
            .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.RegenerateInvoiceEstimateParams;
import com.chargebee.v4.models.estimate.responses.RegenerateInvoiceEstimateResponse;

public class RegenerateInvoiceEstimate {

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

        RegenerateInvoiceEstimateParams params = RegenerateInvoiceEstimateParams.builder()
            .invoiceImmediately(true)
            .build();

        RegenerateInvoiceEstimateResponse response = client
            .estimates()
            .regenerateInvoiceEstimate("__test__KyVnOuSHufvfo16", 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.regenerateInvoiceEstimate("__test__KyVnOuSHufvfo16", {
        invoice_immediately: true
    });

    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()->regenerateInvoiceEstimate("__test__KyVnOuSHufvfo16", [
    "invoice_immediately" => true
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Estimate.regenerate_invoice_estimate("__test__KyVnOuSHufvfo16",
    cb_client.Estimate.RegenerateInvoiceEstimateParams(
        invoice_immediately=True
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Estimate.regenerate_invoice_estimate("__test__KyVnOuSHufvfo16",{
  :invoice_immediately => "true"
})

estimate = result.estimate
```

### Regenerate For Custom Term

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__KyVnOuSHufpzqv/regenerate_invoice_estimate \
     -u {site_api_key}:\
     -d invoice_immediately="false" \
     -d date_from=1518344700 \
     -d date_to=1519381500 \
     -d prorate="true"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Estimate.RegenerateInvoiceEstimate("__test__KyVnOuSHufpzqv")
		.InvoiceImmediately(false)
		.DateFrom(1518344700)
		.DateTo(1519381500)
		.Prorate(true)
		.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.RegenerateInvoiceEstimate("__test__KyVnOuSHufpzqv", &estimate.RegenerateInvoiceEstimateRequestParams{
        InvoiceImmediately : chargebee.Bool(false),
        DateFrom : chargebee.Int64(1518344700),
        DateTo : chargebee.Int64(1519381500),
        Prorate : chargebee.Bool(true),
    }).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.EstimateRegenerateInvoiceEstimateRequest{
    InvoiceImmediately : chargebee.Bool(false),
    DateFrom : chargebee.Int64(1518344700),
    DateTo : chargebee.Int64(1519381500),
    Prorate : chargebee.Bool(true),
}
  res, err := client.Estimate.RegenerateInvoiceEstimate("__test__KyVnOuSHufpzqv", 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.regenerateInvoiceEstimate("__test__KyVnOuSHufpzqv")
            .invoiceImmediately(false)
            .dateFrom(new Timestamp(1518344700L * 1000))
            .dateTo(new Timestamp(1519381500L * 1000))
            .prorate(true)
            .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.RegenerateInvoiceEstimateParams;
import com.chargebee.v4.models.estimate.responses.RegenerateInvoiceEstimateResponse;
import java.sql.Timestamp;

public class RegenerateInvoiceEstimate {

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

        RegenerateInvoiceEstimateParams params = RegenerateInvoiceEstimateParams.builder()
            .invoiceImmediately(false)
            .dateFrom(new Timestamp(1518344700L * 1000))
            .dateTo(new Timestamp(1519381500L * 1000))
            .prorate(true)
            .build();

        RegenerateInvoiceEstimateResponse response = client
            .estimates()
            .regenerateInvoiceEstimate("__test__KyVnOuSHufpzqv", 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.regenerateInvoiceEstimate("__test__KyVnOuSHufpzqv", {
        invoice_immediately: false,
        date_from: 1518344700,
        date_to: 1519381500,
        prorate: true
    });

    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()->regenerateInvoiceEstimate("__test__KyVnOuSHufpzqv", [
    "invoice_immediately" => false,
    "date_from" => 1518344700,
    "date_to" => 1519381500,
    "prorate" => true
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Estimate.regenerate_invoice_estimate("__test__KyVnOuSHufpzqv",
    cb_client.Estimate.RegenerateInvoiceEstimateParams(
        invoice_immediately=False,
        date_from=1518344700,
        date_to=1519381500,
        prorate=True
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Estimate.regenerate_invoice_estimate("__test__KyVnOuSHufpzqv",{
  :invoice_immediately => "false",
  :date_from => 1518344700,
  :date_to => 1519381500,
  :prorate => "true"
})

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1517480722,
    "invoice_estimate": {
      "amount_due": 895,
      "amount_paid": 0,
      "credits_applied": 0,
      "currency_code": "USD",
      "customer_id": "__test__KyVnOuSHufvfo16",
      "date": 1517480722,
      "line_item_discounts": {},
      "line_item_taxes": {},
      "line_items": [
        {
          "amount": 895,
          "customer_id": "__test__KyVnOuSHufvfo16",
          "date_from": 1517480722,
          "date_to": 1519899922,
          "description": "No Trial",
          "discount_amount": 0,
          "entity_id": "no_trial",
          "entity_type": "plan",
          "id": "li___test__KyVnOuSHufvn81H",
          "is_taxed": false,
          "item_level_discount_amount": 0,
          "object": "line_item",
          "pricing_model": "per_unit",
          "quantity": 1,
          "subscription_id": "__test__KyVnOuSHufvfo16",
          "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",
      "id": "__test__KyVnOuSHufvfo16",
      "next_billing_at": 1519899922,
      "object": "subscription_estimate",
      "status": "active"
    }
  }
}
```

## URL Format

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

## Input Parameters

- `date_from` (optional, timestamp(UTC) in seconds)
  The start date of the period being invoiced. The default value is [current\_term\_start](/docs/api/subscriptions/subscription-object#current_term_start) .

- `date_to` (optional, timestamp(UTC) in seconds)
  The end date of the period being invoiced. The default value is [current\_term\_end](/docs/api/subscriptions/subscription-object#current_term_end) .

- `prorate` (optional, boolean)
  Whether the charges should be prorated according to the term specified by `date_from` and `date_to`. Should not be passed without `date_from` and `date_to` .

- `invoice_immediately` (optional, boolean)
  Only applicable when [Consolidated Invoicing](https://www.chargebee.com/docs/consolidated-invoicing.html ) is enabled for the customer. Set to `false` to leave the current term charge for the subscription as [unbilled](https://www.chargebee.com/docs/unbilled-charges.html ). Once you have done this for all suitable subscriptions of the customer, call [Create an invoice for unbilled charges](/docs/api/unbilled_charges/create-an-invoice-for-unbilled-charges) to invoice them.

## Returns

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