Change the tax on an invoice
AI agents: read /llms.txt; add .md to any page URL. This page as Markdown: /reference/invoices/v2-invoice-tax-selection-update.md. Index of every page and the rules for every call: /llms.txt. Guides and concepts in one file: /llms-full.txt. OpenAPI: /openapi.json.
PUT/
Sets, changes or removes an invoice's tax line. An invoice has at most one: US Auto Tax (auto_tax), a tax preset (user_tax) or a tax set by hand (override_tax).
Send what you expect the current tax line to be (expected_tax: its id and lock_version, or null) and what you want (desired_tax, or null to remove it). If someone changed the tax since you read the invoice, nothing changes and you get 422 invoice_tax_conflict: read the invoice again and retry.
Returns action_performed (CREATED, UPDATED, REPLACED, DELETED or NONE), has_changes, the tax line (tax) and lock versions. With auto_tax, YoPrint asks its tax provider for the rate while you wait (it charges no tax when the team has no US nexus, the customer is tax exempt, or the destination is outside the US).
Business rules
- Both
expected_taxanddesired_taxmust be present; null is allowed for either. Missing: 422 "The expected_tax field must be present." expected_taxmust match the current tax line exactly (id andlock_version), or be null when there is none. Otherwise 422invoice_tax_conflict: "Invoice tax changed in another window. Reload and retry."- A different
typefrom the current one replaces the line (new id); the same type updates it; null deletes it. - A tax line you set is yours: YoPrint no longer manages it, even on an Auto Invoice invoice.
- Auto Tax needs a US plan with Auto Tax turned on: otherwise 422
cart_item_validation_errorwitherror.context.reasonauto_tax_unavailable. - Synced (external) invoices are read-only here: 422
external_invoice_tax_snapshot_read_only. - An invoice with more than one tax line can't be changed here: 422
invoice_tax_invariant_violation.
Side effects
- Recalculates the invoice's tax and total, the order's invoiced totals, and redistributes (reallocates) the order's recorded payments across its invoices.
auto_taxcalls the tax provider (address lookup and rate) while you wait; it recalculates on every call.- May queue a QuickBooks Online sync of the order. Open Admin Portal pages refresh, and so do Customer Portal pages the order's customer has open.
Path parameters
Your team slug, shown as Team ID next to your API key in Profile.
- Example
your-team
- Example
The invoice's
id(a hash id), as its answers show it. Its unique key (ordinv_...) also works, but API answers don't include it.- Example
cBRpSf5nw6upt5
- Example
Request body
application/json, required.
The tax you want, or null to remove the tax line.
Child fields (2)
propertiesobjectThe fields of that kind, as for an invoice line of that
product.type:auto_taxtakesengineus,from,toandrate;user_taxtakes the presetid;override_taxtakesmodeandtotal.typestringauto_tax(US Auto Tax),user_tax(one of your tax presets) oroverride_tax(set by hand).- One of:
"auto_tax","user_tax","override_tax"
- One of:
The tax line you think is there now: its
idandlock_versionfrom the invoice's items, or null when it has none. If it doesn't match, nothing changes (422invoice_tax_conflict).Child fields (2)
idstringThe current tax line.
lock_versionintegerThat line's
lock_version.- Minimum 0
More examples (3)
Mark tax exempt
curl -X PUT 'https://secure.yoprint.com/v2/api/store/your-team/v2/invoice/cBRpSf5nw6upt5/tax-selection' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Accept: application/json' \ -H 'X-Yoprint-Decimal-Format: exact-v1' \ -H 'Content-Type: application/json' \ -d '{ "desired_tax": { "properties": { "mode": "tax_exempt", "total": { "dp": 0, "value": 0 } }, "type": "override_tax" }, "expected_tax": { "id": "WzHB84GM5mzqAw", "lock_version": 1730000000000001 } }'Use a tax preset on an invoice with no tax
curl -X PUT 'https://secure.yoprint.com/v2/api/store/your-team/v2/invoice/cBRpSf5nw6upt5/tax-selection' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Accept: application/json' \ -H 'X-Yoprint-Decimal-Format: exact-v1' \ -H 'Content-Type: application/json' \ -d '{ "desired_tax": { "properties": { "id": "KC48n7qAAfGYMM" }, "type": "user_tax" }, "expected_tax": null }'Remove the tax line
curl -X PUT 'https://secure.yoprint.com/v2/api/store/your-team/v2/invoice/cBRpSf5nw6upt5/tax-selection' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Accept: application/json' \ -H 'X-Yoprint-Decimal-Format: exact-v1' \ -H 'Content-Type: application/json' \ -d '{ "desired_tax": null, "expected_tax": { "id": "WzHB84GM5mzqAw", "lock_version": 1730000000000001 } }'Response
200Successful response.
Child fields (5)
object_typestring- Always
"invoice_tax_selection"
- Always
action_performedstring- One of:
"CREATED","UPDATED","REPLACED","DELETED","NONE"
- One of:
has_changesbooleanlock_versionobjectLock versions after the call.
taxobject | nullThe tax line after the call (a tax line has
productbut nopricing,quantityortaxgroup), or null when there is none.Child fields (15)
_metaobjectRead-only:
id,type,invoice_id,lock_version,from_legacy,position_hash.auto_invoice_managedbooleanYoPrint manages this line (Auto Invoice).
external_idsarray of objectsLinks to external systems; empty for lines made in YoPrint.
external_typestring | nullfrom_legacybooleanidstringThe invoice line.
invoice_idstringThe invoice.
is_externalbooleanlock_versionintegerSend it back on Update an invoice line to detect a concurrent change.
positionintegerpricingobjectAbsent on tax and discount lines.
system(sales order lines):_meta.unit_priceis the price copied from the sales order line and_meta.subtotalis that price × this line's quantity.fee(shipping fees):product.totalis the fee. Prices come at the stored scale (6 decimal places);_meta.subtotalat the combined scale of price × quantity (compacted when large). Always readdp.Child fields (1)
typestring- One of:
"system","fee"
- One of:
productobjectChild fields (3)
_metaobjectRead-only details, always an object (with
editable_fields_on_update); fororder_item,parentdescribes the sales order line.propertiesobjectThe kind's fields; for
order_item,idis the sales order line. A discount's percentage or amount comes back astotal(you send it asrate).typestring- One of:
"order_item","shipment_fee","invoice_discount","user_tax","override_tax","auto_tax","invoice_surcharge"
- One of:
quantityobjectAbsent on tax and discount lines.
Child fields (2)
typestring- Always
"unit"
- Always
totaldecimal pairThe quantity. A decimal pair: the amount is
value÷ 10^dp({ "value": 1250, "dp": 2 }is 12.50). Readdpevery time: it can differ between fields and records.- See Money and quantities.
taxobjectAbsent on tax and discount lines. YoPrint adds it by default only to sales order lines (
taxable); other lines have it only when it was sent.Child fields (1)
typestring- One of:
"taxable","non_taxable"
- One of:
typestringSame as
product.type.
Errors
401The API key is missing or wrong (
unauthenticated).403You are not allowed to do this.
api_access_not_in_plan: your team's plan doesn't include API access (Pro and above, with an active subscription or trial), so every request answers this until the team upgrades. When your role lacks the permission the operation needs, the body is only{"message": "Insufficient Permission"}. Other refusals use the error envelope, withunauthorizedoruser_is_not_authorized.404Not found.
page_not_found: the team slug is unknown, you are not a member of the team, or an id in the path is not one of this team's.code: null, with a message that starts "No query results for": there is no record with that id.- When
- The invoice isn't your team's.
- Fix
- Check the id.
422The request was refused and changed nothing.
validation_failedlists what to fix inerror.fields; other codes name a business rule, explained inerror.message. A few checks answer with only{"message": "..."}. An operation that calls another service (a payment provider, a carrier, an accounting app) can answerconnect_timeout("Please retry again") when that service does not answer in time: the change may or may not have happened there, so read the record back before you retry.- When
invoice_tax_conflict: the tax changed since you read it.- Fix
- Read the invoice, take the current tax line's id and
lock_version, and retry. - When
- A missing key, an unknown
type, or bad properties (validation_failed). - Fix
- Fix the fields named in the error.
- When
- An unknown tax preset, or Auto Tax couldn't be calculated. These come back as a bare
{ "message": ... }("user_tax: User Tax ID Not found", "auto_tax: Auto Tax calculation failed. Please retry later."). - Fix
- Check the preset id; retry Auto Tax later.
Related
- GETGet an invoice
/v2/ api/ store/ {team_slug}/ v2/ invoice/ {unique_key} - PUTUpdate an invoice
/v2/ api/ store/ {team_slug}/ v2/ invoice/ {unique_key} - GETList tax presets
/v1/ api/ store/ {team_slug}/ setting/ tax_type
