# Record tax withheld for an invoice

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


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

Records `[tax_withheld](/docs/api/tax_withheld)` by the customer against the invoice specified. This operation is allowed only when all of the following conditions are true:

-   Tax Amount Withheld is enabled.
-   The `invoice` does not have a `linked_taxes_withheld` record associated with it already.
-   `invoice.amount_due` is greater than zero.
-   `invoice.status` is one of the following: `payment_due`, `not_paid`, or `posted`.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/__demo_inv__4/record_tax_withheld \
     -u {site_api_key}:\
     -d "tax_withheld[amount]"=200 \
     -d "tax_withheld[date]"=1635080065
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.RecordTaxWithheld("__demo_inv__4")
		.TaxWithheldAmount(200)
		.TaxWithheldDate(1635080065)
		.Request();

Invoice invoice = result.Invoice;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    invoiceAction "github.com/chargebee/chargebee-go/v3/actions/invoice"
    "github.com/chargebee/chargebee-go/v3/models/invoice"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := invoiceAction.RecordTaxWithheld("__demo_inv__4", &invoice.RecordTaxWithheldRequestParams{
        TaxWithheld : &invoice.RecordTaxWithheldTaxWithheldParams{
            Amount : chargebee.Int64(200),
            Date : chargebee.Int64(1635080065),
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### 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.InvoiceRecordTaxWithheldRequest{
    TaxWithheld : &chargebee.InvoiceRecordTaxWithheldTaxWithheld{
        Amount : chargebee.Int64(200),
        Date : chargebee.Int64(1635080065),
    },
}
  res, err := client.Invoice.RecordTaxWithheld("__demo_inv__4", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### 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 = Invoice.recordTaxWithheld("__demo_inv__4")
            .taxWithheldAmount(200L)
            .taxWithheldDate(new Timestamp(1635080065L * 1000))
            .request();

        Invoice invoice = result.invoice();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.invoice.params.InvoiceRecordTaxWithheldParams;
import com.chargebee.v4.models.invoice.responses.InvoiceRecordTaxWithheldResponse;
import java.sql.Timestamp;

public class InvoiceRecordTaxWithheld {

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

        InvoiceRecordTaxWithheldParams.TaxWithheldParams taxWithheldParams =
            InvoiceRecordTaxWithheldParams.TaxWithheldParams.builder()
                .amount(200L)
                .date(new Timestamp(1635080065L * 1000))
                .build();

        InvoiceRecordTaxWithheldParams params = InvoiceRecordTaxWithheldParams.builder()
            .taxWithheld(taxWithheldParams)
            .build();

        InvoiceRecordTaxWithheldResponse response = client
            .invoices()
            .recordTaxWithheld("__demo_inv__4", params);

        Invoice invoice = response.getInvoice();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.invoice.recordTaxWithheld("__demo_inv__4", {
        tax_withheld: {
            amount: 200,
            date: 1635080065
        }
    });

    console.log(result);
    const invoice = result.invoice;
} 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->invoice()->recordTaxWithheld("__demo_inv__4", [
    "tax_withheld" => [
        "amount" => 200,
        "date" => 1635080065
    ]
]);
$invoice = $result->invoice;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.record_tax_withheld("__demo_inv__4",
    cb_client.Invoice.RecordTaxWithheldParams(
        tax_withheld=cb_client.Invoice.RecordTaxWithheldTaxWithheldParams(
            amount=200,
            date=1635080065
        )
    )
)
invoice = response.invoice
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.record_tax_withheld("__demo_inv__4",{
  :tax_withheld => {
    :amount => 200,
    :date => 1635080065
  }
})

invoice = result.invoice
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 800,
    "amount_paid": 0,
    "amount_to_collect": 800,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "Rachel",
      "last_name": "Green",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "channel": "web",
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8asr8SmwH1ZM2w",
    "date": 1635076461,
    "deleted": false,
    "due_date": 1635076461,
    "dunning_attempts": [
      {
        "attempt": 0,
        "created_at": 1635076462,
        "dunning_type": "auto_collect",
        "retry_engine": "chargebee",
        "transaction_id": "txn___test__8asr8SmwH4Z83z",
        "txn_amount": 1000,
        "txn_status": "failure"
      },
      {..}
    ],
    "dunning_status": "in_progress",
    "exchange_rate": 1,
    "first_invoice": false,
    "generated_at": 1635076461,
    "has_advance_charges": false,
    "id": "__demo_inv__4",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__8asr8SmwH1ZM2w",
        "date_from": 1635076461,
        "date_to": 1635162861,
        "description": "Basic USD 2",
        "discount_amount": 0,
        "entity_id": "basic-USD2",
        "entity_type": "plan_item_price",
        "id": "li___test__8asr8SmwH4WO3y",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8asr8SmwH1ZM2w",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1635076462,
        "txn_amount": 1000,
        "txn_date": 1635076462,
        "txn_id": "txn___test__8asr8SmwH4Z83z",
        "txn_status": "failure"
      },
      {..}
    ],
    "linked_taxes_withheld": [
      {
        "amount": 200,
        "date": 1635080065,
        "description": "A tax amount of $2.00 withheld by the customer was recorded against the invoice due amount.",
        "id": "tax_wh___test__8assSSmwH5Bhr"
      },
      {..}
    ],
    "net_term_days": 0,
    "next_retry_at": 1635162862,
    "object": "invoice",
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1517478871359,
    "round_off_amount": 0,
    "status": "payment_due",
    "sub_total": 1000,
    "subscription_id": "__test__8asr8SmwH1ZM2w",
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1517478871,
    "write_off_amount": 0
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/invoices/{invoice-id}/record_tax_withheld

## Input Parameters

- `tax_withheld` (optional, in cents)
  Parameters for tax\_withheld
  - `amount` (required, in cents, min=1)
    The amount withheld by the customer as tax from the invoice. This must not exceed `[invoice.amount_due](/docs/api/invoices/invoice-object#amount_due)`. The unit depends on the [type of currency](/docs/api/getting-started).
  - `reference_number` (optional, string, max chars=100)
    A unique external reference number for the tax withheld. Typically, this is the reference number used by the system you are integrating the API with. Depending on your integration, this could be the reference number issued by the taxation authority to identify the customer or the specific tax transaction.
  - `date` (optional, timestamp(UTC) in seconds)
    Date or time associated with this tax amount withheld. The default value is the time of invoking this operation.
  - `description` (optional, string, max chars=65k)
    The description for this tax withheld.

## Returns

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