# Create an estimate for unbilled charges

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


This is similar to the "Create an invoice for unbilled charges" API but no invoice will be created, only an estimate for this operation is created.

In the estimate response,

-   **estimate.invoice\_estimates** is an array of **estimate.invoice\_estimate**. This has the details of the invoices that will be generated now.

**Note:**

-   This API when invoked does not perform the actual operation. It just generates an estimate.
-   Both _subscription\_id_ and _customer\_id_ parameters should not be given at the same time.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/unbilled_charges/invoice_now_estimate \
     -u {site_api_key}:\
     -d customer_id="__test__8aszcSOcqyER6Q"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = UnbilledCharge.InvoiceNowEstimate()
		.CustomerId("__test__8aszcSOcqyER6Q")
		.Request();

Estimate estimate = result.Estimate;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    unbilledchargeAction "github.com/chargebee/chargebee-go/v3/actions/unbilledcharge"
    "github.com/chargebee/chargebee-go/v3/models/unbilledcharge"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := unbilledchargeAction.InvoiceNowEstimate(&unbilledcharge.InvoiceNowEstimateRequestParams{
        CustomerId : "__test__8aszcSOcqyER6Q",
    }).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.UnbilledChargeInvoiceNowEstimateRequest{
    CustomerId : "__test__8aszcSOcqyER6Q",
}
  res, err := client.UnbilledCharge.InvoiceNowEstimate(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 = UnbilledCharge.invoiceNowEstimate()
            .customerId("__test__8aszcSOcqyER6Q")
            .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.unbilledCharge.params.UnbilledChargeInvoiceNowEstimateParams;
import com.chargebee.v4.models.unbilledCharge.responses.UnbilledChargeInvoiceNowEstimateResponse;

public class UnbilledChargeInvoiceNowEstimate {

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

        UnbilledChargeInvoiceNowEstimateParams params = UnbilledChargeInvoiceNowEstimateParams.builder()
            .customerId("__test__8aszcSOcqyER6Q")
            .build();

        UnbilledChargeInvoiceNowEstimateResponse response = client.unbilledCharges().invoiceNowEstimate(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.unbilledCharge.invoiceNowEstimate({
        customer_id: "__test__8aszcSOcqyER6Q"
    });

    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->unbilledCharge()->invoiceNowEstimate([
    "customer_id" => "__test__8aszcSOcqyER6Q"
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.UnbilledCharge.invoice_now_estimate(
    cb_client.UnbilledCharge.InvoiceNowEstimateParams(
        customer_id="__test__8aszcSOcqyER6Q"
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::UnbilledCharge.invoice_now_estimate({
  :customer_id => "__test__8aszcSOcqyER6Q"
})

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1517495910,
    "invoice_estimates": [
      {
        "amount_due": 1100,
        "amount_paid": 0,
        "credits_applied": 0,
        "currency_code": "USD",
        "customer_id": "__test__8aszcSOcqyER6Q",
        "date": 1517495910,
        "line_item_discounts": {},
        "line_item_taxes": {},
        "line_items": [
          {
            "amount": 1000,
            "customer_id": "__test__8aszcSOcqyER6Q",
            "date_from": 1517495909,
            "date_to": 1519915109,
            "description": "basic USD",
            "discount_amount": 0,
            "entity_id": "basic-USD",
            "entity_type": "plan_item_price",
            "id": "li___test__8aszcSOcqyMd6V",
            "is_taxed": false,
            "item_level_discount_amount": 0,
            "object": "line_item",
            "pricing_model": "per_unit",
            "quantity": 1,
            "subscription_id": "__test__8aszcSOcqyJP6T",
            "tax_amount": 0,
            "unit_amount": 1000
          },
          {..}
        ],
        "object": "invoice_estimate",
        "price_type": "tax_exclusive",
        "recurring": true,
        "round_off_amount": 0,
        "sub_total": 1100,
        "taxes": {},
        "total": 1100
      },
      {..}
    ],
    "object": "estimate"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/unbilled_charges/invoice_now_estimate

## Input Parameters

- `subscription_id` (optional, string, max chars=50)
  Identifier of the subscription for which this estimate needs to be created. Should be given if 'customer\_id' is not specified.

- `customer_id` (optional, string, max chars=50)
  Identifier of the customer for whom this estimate is created. Is given if 'subscription\_id' is not specified. Applicable only if the 'Consolidated Invoicing' is enabled. If 'Consolidated Invoicing' is not enabled, an invoice will be generated for every subscription.

## Returns

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