# Convert a quote

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


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

This API is to convert a quote to an invoice.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/quotes/1/convert \
     -X POST  \
     -u {site_api_key}:
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Quote.Convert("1").Request();

Quote quote = result.Quote;
QuotedSubscription quotedSubscription = result.QuotedSubscription;
QuotedCharge quotedCharge = result.QuotedCharge;
QuotedRamp quotedRamp = result.QuotedRamp;
Customer customer = result.Customer;
Subscription subscription = result.Subscription;
Invoice invoice = result.Invoice;
CreditNote creditNote = result.CreditNote;
List<UnbilledCharge> unbilledCharges = result.UnbilledCharges;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    quoteAction "github.com/chargebee/chargebee-go/v3/actions/quote"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := quoteAction.Convert("1", nil).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Quote := res.Quote
        QuotedSubscription := res.QuotedSubscription
        QuotedCharge := res.QuotedCharge
        QuotedRamp := res.QuotedRamp
        Customer := res.Customer
        Subscription := res.Subscription
        Invoice := res.Invoice
        CreditNote := res.CreditNote
        UnbilledCharges := res.UnbilledCharges
    }
}
```

#### 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.QuoteConvertRequest{}
  res, err := client.Quote.Convert("1", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Quote := res.Quote
        QuotedSubscription := res.QuotedSubscription
        QuotedCharge := res.QuotedCharge
        QuotedRamp := res.QuotedRamp
        Customer := res.Customer
        Subscription := res.Subscription
        Invoice := res.Invoice
        CreditNote := res.CreditNote
        UnbilledCharges := res.UnbilledCharges
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import java.util.List;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Quote.convert("1").request();

        Quote quote = result.quote();
        QuotedSubscription quotedSubscription = result.quotedSubscription();
        QuotedCharge quotedCharge = result.quotedCharge();
        QuotedRamp quotedRamp = result.quotedRamp();
        Customer customer = result.customer();
        Subscription subscription = result.subscription();
        Invoice invoice = result.invoice();
        CreditNote creditNote = result.creditNote();
        List<UnbilledCharge> unbilledCharges = result.unbilledCharges();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.quote.Quote;
import com.chargebee.v4.models.quote.params.QuoteConvertParams;
import com.chargebee.v4.models.quote.responses.QuoteConvertResponse;
import com.chargebee.v4.models.quotedCharge.QuotedCharge;
import com.chargebee.v4.models.quotedRamp.QuotedRamp;
import com.chargebee.v4.models.quotedSubscription.QuotedSubscription;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.util.List;

public class QuoteConvert {

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

        QuoteConvertResponse response = client.quotes().convert("1");

        Quote quote = response.getQuote();
        QuotedSubscription quotedSubscription = response.getQuotedSubscription();
        QuotedCharge quotedCharge = response.getQuotedCharge();
        QuotedRamp quotedRamp = response.getQuotedRamp();
        Customer customer = response.getCustomer();
        Subscription subscription = response.getSubscription();
        Invoice invoice = response.getInvoice();
        CreditNote creditNote = response.getCreditNote();
        List<UnbilledCharge> unbilledCharges = response.getUnbilledCharges();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.quote.convert("1");

    console.log(result);
    const quote = result.quote;
    const quotedSubscription = result.quoted_subscription;
    const quotedCharge = result.quoted_charge;
    const quotedRamp = result.quoted_ramp;
    const customer = result.customer;
    const subscription = result.subscription;
    const invoice = result.invoice;
    const creditNote = result.credit_note;
    const unbilledCharges = result.unbilled_charges;
} 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->quote()->convert("1");
$quote = $result->quote;
$quotedSubscription = $result->quoted_subscription;
$quotedCharge = $result->quoted_charge;
$quotedRamp = $result->quoted_ramp;
$customer = $result->customer;
$subscription = $result->subscription;
$invoice = $result->invoice;
$creditNote = $result->credit_note;
$unbilledCharges = $result->unbilled_charges;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Quote.convert("1")
quote = response.quote
quoted_subscription = response.quoted_subscription
quoted_charge = response.quoted_charge
quoted_ramp = response.quoted_ramp
customer = response.customer
subscription = response.subscription
invoice = response.invoice
credit_note = response.credit_note
unbilled_charges = response.unbilled_charges
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Quote.convert("1")

quote = result.quote
quoted_subscription = result.quoted_subscription
quoted_charge = result.quoted_charge
quoted_ramp = result.quoted_ramp
customer = result.customer
subscription = result.subscription
invoice = result.invoice
credit_note = result.credit_note
unbilled_charges = result.unbilled_charges
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "on",
    "card_status": "valid",
    "created_at": 1517494504,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "John",
    "id": "__test__8aszcSOcl4hbQ",
    "last_name": "Doe",
    "net_term_days": 0,
    "object": "customer",
    "payment_method": {
      "gateway": "chargebee",
      "gateway_account_id": "gw___test__8at1FSOcl3IX1y",
      "object": "payment_method",
      "reference_id": "tok___test__8aszcSOcl4n5R",
      "status": "valid",
      "type": "card"
    },
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "primary_payment_source_id": "pm___test__8aszcSOcl4nKS",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517494504941,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517494504
  },
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 0,
    "amount_paid": 4500,
    "amount_to_collect": 0,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "John",
      "last_name": "Doe",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8aszcSOcl4hbQ",
    "date": 1517494506,
    "deleted": false,
    "due_date": 1517494506,
    "dunning_attempts": {},
    "exchange_rate": 1,
    "first_invoice": true,
    "has_advance_charges": false,
    "id": "__demo_inv__1",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 4000,
        "customer_id": "__test__8aszcSOcl4hbQ",
        "date_from": 1517494506,
        "date_to": 1517494506,
        "description": "Encryption Charge USD Monthly",
        "discount_amount": 0,
        "entity_id": "encryption-charge-USD",
        "entity_type": "charge_item_price",
        "id": "li___test__8aszcSOcl5Bvi",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 4000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 4500,
        "applied_at": 1517494506,
        "txn_amount": 4500,
        "txn_date": 1517494506,
        "txn_id": "txn___test__8aszcSOcl5Fuk",
        "txn_status": "success"
      },
      {..}
    ],
    "net_term_days": 0,
    "new_sales_amount": 4500,
    "object": "invoice",
    "paid_at": 1517494506,
    "price_type": "tax_exclusive",
    "recurring": false,
    "resource_version": 1517494506800,
    "round_off_amount": 0,
    "status": "paid",
    "sub_total": 4500,
    "tax": 0,
    "term_finalized": true,
    "total": 4500,
    "updated_at": 1517494506,
    "write_off_amount": 0
  },
  "quote": {
    "amount_due": 4500,
    "amount_paid": 0,
    "billing_address": {
      "first_name": "John",
      "last_name": "Doe",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "charge_on_acceptance": 4500,
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8aszcSOcl4hbQ",
    "date": 1517494506,
    "id": "1",
    "invoice_id": "__demo_inv__1",
    "line_item_discounts": {},
    "line_item_taxes": {},
    "line_items": [
      {
        "amount": 4000,
        "customer_id": "__test__8aszcSOcl4hbQ",
        "date_from": 1517494505,
        "date_to": 1517494505,
        "description": "Encryption Charge USD Monthly",
        "discount_amount": 0,
        "entity_id": "encryption-charge-USD",
        "entity_type": "charge_item_price",
        "id": "__test__8aszcSOcl55eb",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "tax_amount": 0,
        "unit_amount": 4000
      },
      {..}
    ],
    "object": "quote",
    "operation_type": "onetime_invoice",
    "price_type": "tax_exclusive",
    "resource_version": 1517494506843,
    "status": "invoiced",
    "sub_total": 4500,
    "taxes": {},
    "total": 4500,
    "total_payable": 4500,
    "updated_at": 1517494506,
    "valid_till": 1526134505,
    "version": 1
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/quotes/{quote-id}/convert

## Input Parameters

- `invoice_date` (optional, timestamp(UTC) in seconds)
  The document date displayed on the invoice PDF. Provide this value to backdate the invoice. Backdating an invoice is done for reasons such as booking revenue for a previous date or when the subscription is effective as of a past date. When not provided, the value is the same as current date. Moreover, if the invoice is created as `pending` , and if the site is configured to set invoice dates to date of closing, then upon invoice closure, this date is changed to the invoice closing date. `taxes` and `line_item_taxes` are computed based on the tax configuration as of `invoice_date`. When passing this parameter, the following prerequisites must be met:
  
  -   `invoice_date` must be in the past.
  -   `invoice_date` is not 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.
  -   The date is not earlier than `quoted_subscription.start_date` or `quoted_subscription.changes_scheduled_at` (whichever is applicable).
  -   `invoice_immediately` must be `true`. .

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

- `create_pending_invoices` (optional, boolean)
  This attribute is set to `true` automatically for the subscription when it has one or more `metered` items. However, when there are no `metered` items, you can pass this parameter as `true` to force all invoices (except the first) to be created as `pending`. This is useful in the following scenarios:
  
  -   When you manage metered billing at your end by calculating usage-based charges yourself and add them to the subscription as [one-time charges](https://www.chargebee.com/docs/2.0/charges.html).
  -   When your workflow involves inspecting all charges before you close invoices.
  
  **Note:**
  
  -   You must enable [Metered Billing](https://www.chargebee.com/docs/billing/2.0/usage-based-billing/metered_billing) for this parameter to be acceptable.
  -   To create the first invoice also as `pending`, pass `first_invoice_pending` as `true`.
  
  .

- `first_invoice_pending` (optional, boolean, default=false)
  Non-metered items are billed at the beginning of a billing cycle while metered items are billed at the end. Consequently, the first invoice of the subscription contains only the non-metered items.
  
  By passing this parameter as `true`, you create the first invoice as `pending` allowing you to add the previous term's metered charges to it before closing. This is useful when the subscription is moved to Chargebee from a different billing system. As applicable to all `pending` invoices, this invoice is also [closed automatically](https://www.chargebee.com/docs/billing/2.0/usage-based-billing/metered_billing#configuring-metered-billing) or via an [API call](/docs/api/invoices/close-a-pending-invoice).
  
  **Note:**
  
  This parameter is passed only when there are metered items in the subscription or when `create_pending_invoices` is `true`.
  
  .

- `subscription` (optional, string)
  Parameters for subscription
  - `id` (optional, string, max chars=50)
    Applicable only for create subscription quote.
  - `auto_collection` (optional, enumerated string)
    Applicable only for create subscription quote.
    Possible enum values:
      - `on`
        Whenever an invoice is created for this subscription, an automatic charge will be attempted on the payment method available.
      - `off`
        Automatic collection of charges will not be made for this subscription. Use this for offline payments.
  - `po_number` (optional, string, max chars=100)
    Purchase order number for this subscription.
  - `auto_close_invoices` (optional, boolean)
    When [auto-closing of invoices](https://www.chargebee.com/docs/billing/2.0/usage-based-billing/metered_billing#configuring-metered-billing) is enabled for the site, you can pass this parameter as `false` to prevent the automatic closing of invoices for this subscription. The value passed here takes precedence over the value stored at the [customer level](/docs/api/customers/customer-object#auto_close_invoices) .

## Returns

- `quote` (Quote object)
  Resource object representing quote

- `quoted_subscription` (Quoted subscription object)
  Resource object representing quoted\_subscription

- `quoted_charge` (Quoted charge object)
  Resource object representing quoted\_charge

- `quoted_ramp` (Quoted ramp object)
  Resource object representing quoted\_ramp

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

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

- `invoice` (Invoice object)
  Resource object representing invoice

- `credit_note` (Credit note object)
  Resource object representing credit\_note

- `unbilled_charges` (optional)
  Resource object representing unbilled\_charge
