---
title: REST API – Taxes, Tax Regions, and Territorial Rules
description: "The API provides access to all settings on the **Tax Calculation** screen: taxes and their calculation methods, fees and their amounts by region, tax regions, the region for each country, territorial exceptions, automatic suggestion, and the address tester. Validation controls…"
url: "https://www.kafinea.com/en/help/api/rest-api-taxes-tax-regions-and-territorial-rules/"
updated: "2026-11-22"
category: API
---

# REST API – Taxes, Tax Regions, and Territorial Rules

The API provides access to all settings on the **Tax Calculation** screen: taxes and their calculation methods, fees and their amounts by region, tax regions, the region for each country, territorial exceptions, automatic suggestion, and the address tester. Validation controls match those of the UI: whatever is rejected by the screen is rejected by the API with the same error reason.

All three operations use the [REST API](https://www.kafinea.com/en/help/api/rest-api-introduction/) session and are restricted to **administrator** accounts.

| Operation | Method | Result |
| --- | --- | --- |
| `tax_region_configuration` | GET | Complete configuration and consistency checks |
| `tax_region_preview` | GET | Region for an address, and suggestion for a new document, without saving anything |
| `tax_region_configure` | POST | A modification, validated and saved in a single step |

The `input` parameter is a JSON object. Checkboxes (`enabled`, `active`, `taxable`, `documentTest`, `intravatApproved`) expect a true JSON boolean: the string `"false"` is rejected.

---

## 1. Read configuration

`tax_region_configuration` takes no parameters.

```bash
curl 'https://apps.kafinea.com/YourKafinea/webservice.php?operation=tax_region_configuration&sessionName=YOUR_SESSION_ID'
```

| Key of `result.configuration` | Content |
| --- | --- |
| `regions` | Numeric ID and name of each tax region |
| `taxes` | Each item tax (`appliesTo: product`) and fee tax (`shipping`), including inactive ones: `taxId`, name, `active`, calculation method `method`, type, `compoundOn`, default rate `defaultRate`, and rates by region `ratesByRegionId` |
| `charges` | Each fee from the **Fees (& their taxes)** tab: `chargeId`, name, `format`, type, default amount `defaultValue`, amounts by region `valuesByRegionId`, `taxable`, and applied taxes `taxIds` |
| `countries` | Each country: identifier, ISO code, base region, business and individual regions, business condition |
| `rules` | Territorial exceptions, active or inactive, with their criterion and priority |
| `enabled`, `departure_country`, `operation_kind`, `organization_ids` | Automatic suggestion and its scope |
| `diagnostics` | `configurationIssues` (duplicate countries, overlapping exceptions, deleted region) and `missingRates` (missing rates for a used region) |

The identifiers in this response are those to be sent back in updates. They vary from one instance to another: retrieve them from the target instance.

---

## 2. Test an address or a new document

`tax_region_preview` receives the address in `input`: `country` (ISO code, French or English name), `postcode`, and `state`.

```bash
curl -G 'https://apps.kafinea.com/YourKafinea/webservice.php' 
  --data-urlencode 'operation=tax_region_preview' 
  --data-urlencode 'sessionName=YOUR_SESSION_ID' 
  --data-urlencode 'input={"country":"France","postcode":"97300"}'
```

The response returns the recognized country, the geographic region (`geography`), and the rule or country that determined it. Using `documentTest: true`, include customer and transaction facts (`partyNature`, `intravatApproved`, `vatNumber`, `organizationId`, `operation`, `goodsOrServices`, `departureCountry`, `partyRegionId`): the response then includes the region that a **new** document would receive (`document`). No facts are inferred. `vatNumber` is the customer's VAT number, formatted as a JSON string; any other data type is rejected.

`organizationId` accepts the company ID or its exact name (also via `organizationName`). A missing or unknown company, or a name shared by multiple companies, is reported in `inputIssues`, along with the configured companies.

When the transaction context does not permit suggesting a region, `document.advisories` contains `UNSUPPORTED_TAX_CONTEXT` and `document.advisory_details` specifies the reason:

| `cause` | Meaning |
| --- | --- |
| `ORGANIZATION_NOT_CONFIGURED` | The company is not among the companies selected for automatic selection |
| `OPERATION_KIND_NOT_SUPPORTED` | The transaction does not involve goods |
| `DEPARTURE_COUNTRY_NOT_CONFIGURED` | The departure country in the settings is missing or not recognized |
| `DEPARTURE_COUNTRY_UNKNOWN` | The provided departure country is missing or not recognized |
| `DEPARTURE_COUNTRY_MISMATCH` | The provided departure country differs from the configured departure country |
| `MODULE_NOT_SUPPORTED` | The document is not a sales document |
| `OPERATION_NOT_SALE` | The transaction is not a sale |

Each entry also provides the received value (`actual`), the expected value (`expected`), and a human-readable `message`, for example: "Company 0 is not among the companies configured for automatic region selection: 530 (My Company)."

To test a modification before saving it, pass `configurationPreview`: the same object as in `tax_region_configure`, extended with `configurationKind` (`settings`, `country`, or `rule`).

---

## 3. Modify configuration

`tax_region_configure` receives `kind` and the complete modification object `input`.

| `kind` | Effect | `input` |
| --- | --- | --- |
| `region` | Creates, renames, or deletes a region | `{"action":"save","name":"…"}` to create; add `region_id` to rename; `{"action":"delete","region_id":12}` to delete |
| `tax_grid` | Replaces the default rate and region rates of an existing tax | `appliesTo`, `taxId`, `defaultRate`, complete `ratesByRegionId`, for example `{"3":0,"5":20}` |
| `tax` | Creates a tax, or redefines an existing tax | `appliesTo`, `name`, `active`, `method` (`Simple`, `Compound` or `Deducted`), `type` (`Fixed` or `Variable`), `defaultRate`, `ratesByRegionId`, `compoundOn`; `taxId` to edit |
| `tax_status` | Enables or disables a tax | `appliesTo`, `taxId`, `active` |
| `charge` | Creates a fee, or redefines an existing fee with its amounts by region | `name`, `format` (`Flat` or `Percent`), `type`, `defaultValue`, `valuesByRegionId`, `taxable`, `taxIds`; `chargeId` to edit |
| `charge_delete` | Deletes a fee | `chargeId` |
| `country` | Changes the region of a country, or of multiple countries at once | `country_id`, `mdstaxregionid`, `mdsprofessionaltaxregionid`, `mdsindividualtaxregionid`, `mdsprofessionaltaxcondition` (`nature_only`, `qualified_customer` or `vat_number`); or `isocodes` containing only the fields to update (see below) |
| `rule` | Creates or updates a territorial exception | `label`, `country`, `criterion_type` (`postcode_prefix`, `postcode_range`, `subdivision`), `criterion_value`, `criterion_end` for a range, `priority`, `active`, the three regions, and the condition; `ruleid` to update |
| `settings` | Enables or configures automatic suggestion | `enabled`, `departure_country`, `operation_kind` (`goods` to enable), `organization_ids` |
| `french_baseline` | Executes **Generate France Tax Settings** | `{}` |

```bash
curl -X POST 'https://apps.kafinea.com/YourKafinea/webservice.php' 
  -d 'operation=tax_region_configure' 
  -d 'sessionName=YOUR_SESSION_ID' 
  -d 'kind=rule' 
  --data-urlencode 'input={"label":"Canaries – Las Palmas","country":"ES","criterion_type":"postcode_prefix","criterion_value":"35","priority":50,"active":true,"mdstaxregionid":5,"mdsprofessionaltaxregionid":0,"mdsindividualtaxregionid":0,"mdsprofessionaltaxcondition":"nature_only"}'
```

In this example, `5` is the identifier of the "Non-EU" region retrieved from the instance. A region value is `0` when unset. The response `{"saved":true,"result":{…}}` returns the created or updated identifier (`region_id`, `ruleid`, `taxId`, `chargeId`). Then re-read the configuration using `tax_region_configuration`, and test several addresses.

The system guarantees match those of the UI:

- a modification is saved entirely or not at all; creating a tax and `french_baseline` are fully validated prior to writing;
- a region still in use by a country, exception, rate table, item, or saved document is retained;
- two active exceptions of equal priority targeting the same address are rejected;
- automatic suggestion can only be enabled if the configuration contains no inconsistencies;
- a zero rate is a configured rate, and a fixed tax maintains an empty table;
- `french_baseline` only fills in missing items and never overwrites an already configured region, rate, or country. Its response lists what was created; if re-executed, it creates nothing.

A rejection starts with a stable error code, such as `LBL_TAX_REGION_INVALID_RULE`, followed by the explanation displayed in the UI and, for an incomplete object, the missing field. Test the code in your integration logic and display the explanation.

Regions can also be read and updated via the [CRUD operations](https://www.kafinea.com/en/help/api/rest-api-full-reference-openapi/) on the module below, subject to the same validation rules:

```text
elementType=MdsTaxRegion   champ : name
```

The condition `vat_number` grants the business region to a business customer whose record contains a VAT number from a country other than the departure country: only the presence of a digit and the two-letter prefix matter, `EL` denotes Greece, and a prefix-free number is accepted. Ticking the **Intra-community exemption authorized** checkbox on the record (`mdsintravatapproved`) also satisfies the condition. Otherwise, the base region applies with notice `VAT_NUMBER_MISSING`.

**Multiple countries at once.** Using `isocodes` (from 1 to 300 ISO codes from the country list) instead of `country_id`, only the submitted fields are updated across each country in the list: each country retains its other fields, ensuring that a custom-configured country is not overridden beyond those fields. The business region must always be passed with its condition. Either all countries are updated, or none; the response lists them in `result.isocodes` and the history retains one line per country. When placed inside `configurationPreview`, the same object can be tested with `tax_region_preview` before being saved.

```bash
curl -X POST 'https://apps.kafinea.com/YourKafinea/webservice.php' 
  -d 'operation=tax_region_configure' 
  -d 'sessionName=YOUR_SESSION_ID' 
  -d 'kind=country' 
  --data-urlencode 'input={"isocodes":["BE","DE","IT"],"mdsprofessionaltaxregionid":6,"mdsprofessionaltaxcondition":"vat_number"}'
```

A country's region should preferably be updated using `kind: "country"`: this is the only operation that also configures business and individual regions. Generic operations on the country module enforce the same safeguards:

```text
elementType=MdsTaxCountry   champs : countryname, isocode, mdstaxregionid, taxzone
```

- `update` and `revise` can update `mdstaxregionid`: the selected region is validated just as in the UI, and previously configured business and individual regions are preserved;
- a country's ISO code cannot be changed (`LBL_TAX_COUNTRY_ISO_IMMUTABLE`); case and whitespace variations are tolerated;
- `create` only accepts an existing ISO code that is not already in the list (`LBL_TAX_COUNTRY_ISO_UNKNOWN`, `LBL_TAX_COUNTRY_ISO_DUPLICATE`);
- `delete` is rejected (`LBL_TAX_COUNTRY_DELETE_REFUSED`): clear the country mapping instead.

Taxes (`Tax`) and item taxes (`ProductTaxes`) can still be read using `retrieve` and `query`, but their generic write operations are rejected (`LBL_TAX_GENERIC_WRITE_REFUSED`, `LBL_PRODUCT_TAXES_GENERIC_WRITE_REFUSED`): taxes must be created and modified using `kind: "tax"`, `tax_grid`, or `tax_status`. Updating a product or service via the API only alters its tax categories if tax fields are explicitly provided (`tax1`, `tax2`…): fields provided with a value replace its entire set of categories, and passing an empty field removes the corresponding category. If no tax fields are supplied, categories remain unchanged.

### Create a tax

A tax is created using `kind: "tax"` without `taxId`. It follows the rules of the **Add Tax** form:

- the name must be unique among taxes of the same scope, including inactive ones;
- the calculation method is selected upon creation and cannot be changed later; to change it, create another tax and disable the former one;
- a compound tax (`Compound`) applies on top of other active simple taxes, listed in `compoundOn`;
- a deducted tax (`Deducted`) applies only to items and remains fixed;
- only a variable tax (`Variable`) accepts rates by region.

```bash
curl -X POST 'https://apps.kafinea.com/YourKafinea/webservice.php' 
  -d 'operation=tax_region_configure' 
  -d 'sessionName=YOUR_SESSION_ID' 
  -d 'kind=tax' 
  --data-urlencode 'input={"appliesTo":"product","name":"Éco-participation","active":true,"method":"Simple","type":"Fixed","defaultRate":0.5,"ratesByRegionId":{},"compoundOn":[]}'
```

Creation adds a column to document lines: taxes cannot be deleted, but they can be disabled using `kind: "tax_status"`. All validation checks occur prior to creation. Next, check the new tax on the relevant products and services.

### Configure fees by region

A variable fee takes an amount per region in `valuesByRegionId`, for example `{"3":15,"5":0}`. The amount `Flat` is stated in the base currency; a fee `Percent` must remain between 0 and 100. A taxable fee lists active fee taxes in `taxIds`.

As in the UI, `kind: "charge_delete"` removes a fee from new documents; saved documents retain their existing amounts. Assign a different name to a new fee. If re-executed, the deletion returns `alreadyDeleted: true`.

---

## 4. With the MCP Server and the Assistant

The MCP server and the Kafinea Assistant use these same operations, subject to their data modification controls. Modifying configuration settings does not recalculate previously saved documents.

---

## 5. Tax region of a document saved via the API

The `create`, `update`, and `revise` operations for quotes, orders, invoices, and credit notes handle field `region_id` as follows:

| `region_id` submitted | Creation | Modification with `LineItems` | Modification without `LineItems` |
| --- | --- | --- | --- |
| missing | suggested region, or customer default region, otherwise none | unchanged | unchanged |
| `null` | treated as missing | region removed | rejected if it differs from the saved region |
| `""` or `0` | explicit absence of region | explicit absence | rejected if it differs from the saved region |
| region ID | this region | this region | rejected if it differs from the saved region |
| other value | rejected (`INVALID_ID_ATTRIBUTE`), nothing is saved | rejected | rejected |

Each line's tax rate depends on the region: a region only changes along with the lines. An update without `LineItems` that changes the region is rejected (`MANDATORY_FIELDS_MISSING`). Submitting the already saved region, for instance after a `retrieve`, remains accepted; `null` and `0` are equivalent here.

Each document maintains its own region: a document's region is never carried over to the document saved immediately after in the same batch.

---

## Related References

- [Tax Configuration](https://www.kafinea.com/en/help/settings/tax-configuration/)
- [Tax Region for Documents](https://www.kafinea.com/fr/documentation/parametrage/la-region-fiscale-des-documents/)
- [Introduction to the REST API](https://www.kafinea.com/en/help/api/rest-api-introduction/)
