Skip to main content
Required permission: expenses The v2 purchase is the same as v1 (same fields, cost centers, and document types) plus currency (currency_code, exchange_rate) and tax_ids required per line. Its errors carry a code; see API v2: what changes.
Unlike sales, saving purchases does not recalculate taxes: FileXpress stores what your system sends (converted to base currency if it carries a currency) and you are the one who calculates them. It only validates that each id in tax_ids exists. An VAT (IVA) amount or amount payable that does not add up is stored as is, so you must send consistent totals.
Fields not described here (observation, is_credit, credit_days, number_control, generation_code, stamp, cost centers, etc.) are those of Register a purchase in v1. Line types remain goods (goods) and services (service).

Register a purchase

Example: a purchase (CCF, tax credit invoice) by a USD-based business, in quetzales (GTQ), with VAT, COTRANS, FOVIAL, VAT withholding, and income tax. The current GTQ rate is 0.128.
All amounts are in the currency of currency_code. The server converts each amount to the base currency using the document’s rate. In the example, 750.00 GTQ taxed is 96.00 USD; the VAT of 97.50 GTQ, 12.48 USD; COTRANS (charge_1), 2.00 USD; FOVIAL (charge_2), 1.00 USD; the 7.50 GTQ withholding, 0.96 USD; and the 10.00 GTQ income tax, 1.28 USD. The total payable of 1,040.94 GTQ is stored as 133.24 USD.
The total payable is netTotals + totalTax + charge_1 + charge_2 − totalRetein − totalRent: 937.50 + 97.50 + 15.63 + 7.81 − 7.50 − 10.00 = 1,040.94.

New or different fields from v1

totals.expenseTotalTax is the taxed base, totalTax the VAT, and charge_1 / charge_2 the special charges (in El Salvador, COTRANS and FOVIAL). If the line carries those fixed taxes in tax_ids, the amounts are recorded per tax. See totals in v1.

Withholding and income tax

totalRetein (VAT withheld) and totalRent (income tax withheld) subtract from the total payable. Example in USD with VAT 26.00, withholding 2.00, and income tax 5.00 on 200.00: expenseTotalToPayment = 200.00 + 26.00 − 2.00 − 5.00 = 219.00.

200 response

For a purchase in base currency: currency_code is the base currency, exchange_rate is "1.00000000", and foreign_total is null.

Errors

They are validated before saving; no error creates the purchase.

Get a purchase

Returns the same as v1 plus the currency reference. The amounts in totals and products are in base currency; the total in the document’s currency is in foreign_total.
A purchase from another business or a nonexistent one responds 404 with { "status": false, "message": "..." }.
GET /payables (v1) also exposes the currency reference of each payable document. See Accounts payable.

Let FileXpress calculate the totals

As in sales, you can omit the total payable and send only the lines: FileXpress calculates the line amounts, VAT, fixed charges, and the total. When it activates: when totals does not include expenseTotalToPayment. What you send per line: sku, name, type (goods or services), quantity, price_before_taxes, discount or discount_percent, taxability (taxed, exempt, not_subject), and tax_ids. You do not need subtotal, expense_taxed, expense_exent, or expense_not_suject: they are filled in automatically. What is calculated
  • VAT: sum of each line’s taxed amount times the rate, rounded at the end.
  • COTRANS (C8) and FOVIAL (D1) as charge_1 and charge_2 (quantity × catalog value), with their row in the purchase’s taxes. They are the only fixed per-unit taxes a purchase can carry today: the purchase only has those two charge slots.
  • totals.totalRetein and totals.totalRent (VAT withholding and income tax) are sent by you: they are the buyer’s decisions. They are subtracted from the amount payable.
Response (data.calculated_totals): netTotals 1234567.89, totalTax 160493.83, expenseTotalToPayment 1382716.04. Amounts are stored exactly: a purchase worth millions does not lose a single cent. The rounding and foreign-currency rules are those of sales. Errors use the same code values (validation_error, tax_invalid).
If a purchase line carries another fixed per-unit tax (from another country or created later in the catalog), the automatic calculation responds 422 with code: "tax_not_supported_in_expenses" and the tax_id in errors, instead of ignoring it and leaving the total wrong. In that case, send the complete totals. Sales do support any fixed tax in the country’s catalog.