# Tax setup

Maintain tax types, dated rate periods, and customer ship-to tax assignments.

Canonical HTML: https://developer.shelfcycle.com/guides/tax-setup

Maintain tax types, dated rate periods, and the tax rate selected for each customer ship-to, with previews and exact readback.

## Access and workflow

Tax reads accept `tax-settings:read` or `tax-settings:write`. Catalog reads require current Settings viewing, Customer viewing, or Customer update permission. Catalog creation, updates, and archiving require the matching Settings automation create, update, or delete permission; period creation uses create permission and period deletion uses delete permission.

Ship-to assignment reads also require Customer view or view-salesperson access and follow customer visibility. Assignment writes additionally need Customer update permission. Only visible, active shipping addresses qualify, including when clearing a rate; a billing-only or archived address returns `404 target_not_found_or_not_visible`.

Full-access keys include both tax scopes. Restricted keys need explicit tax grants; `customers:read` or `customers:write` alone does not grant this access. `GET /me` reports `effectiveCapabilities.taxSettings.view/create/update/archive` and `taxAssignments.view/set`, with matching write-readiness groups.

| Resource | Reads | Writes |
| --- | --- | --- |
| Tax types | GET `/tax-types` or `/tax-types/{taxTypeId}` | POST root, PATCH exact type, POST `/{taxTypeId}/archive` |
| Tax rates | GET `/tax-rates` or `/tax-rates/{taxRateId}` including periods | POST root, PATCH exact rate, POST `/{taxRateId}/archive` |
| Rate periods | Included in rate reads | POST `/tax-rates/{taxRateId}/periods`, DELETE `/tax-rates/{taxRateId}/periods/{periodId}` |
| Ship-to assignments | GET `/tax-assignments` | PUT `/tax-assignments`, POST `/tax-assignments/batch` |

Every write supports `dryRun=true`. Review the returned readiness or per-item results, then remove that query parameter to apply the same intent. Resolve real IDs before replacing the fictional UUIDs in these examples.

## Create and maintain tax types

```bash
curl "$SHELFCYCLE_API_BASE_URL/tax-types?dryRun=true" \
  -X POST \
  -H "Authorization: Bearer $SHELFCYCLE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: tax-setup:sales-tax-type-001" \
  -d '{
    "name":"Sales tax",
    "ledgerAccountId":"11111111-1111-4111-8111-111111111111",
    "basis":"combined",
    "enabled":true,
    "nonCommissionable":true,
    "excludeFromMargin":false
  }'
```

Required fields are `name`, an eligible `ledgerAccountId`, and `basis`: `product`, `non_product`, or `combined`. Optional create settings include `enabled`, `nonCommissionable`, `excludeFromMargin`, `lineDescriptionPattern`, `linesDeletable`, and `linesEditable`.

The ledger account, description pattern, and line-edit/delete flags are fixed at creation. PATCH accepts only `name`, `enabled`, `basis`, `nonCommissionable`, and `excludeFromMargin`, with the type's current `updatedAt` as `If-Match`. A conflicting name returns `409 natural_key_conflict` with the existing ID for review; an unsuitable account returns `422 ledger_account_not_allowed`.

## Create rates and dated periods

```bash
curl "$SHELFCYCLE_API_BASE_URL/tax-rates?dryRun=true" \
  -X POST \
  -H "Authorization: Bearer $SHELFCYCLE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: tax-setup:regional-rate-001" \
  -d '{
    "taxTypeId":"22222222-2222-4222-8222-222222222222",
    "name":"Regional rate",
    "enabled":true,
    "firstPeriod":{"percent":"6.25","effectiveFrom":"2027-01-01"}
  }'
```

Rates require `taxTypeId` and `name`; `enabled` and `firstPeriod` are optional. Each rate keeps its tax type. PATCH changes `name` or `enabled` using that rate's `updatedAt` in `If-Match`.

Add another period through POST `/tax-rates/{taxRateId}/periods` with a stable `Idempotency-Key`, `percent`, `effectiveFrom`, and optional `effectiveEnd`. Percent is a decimal percentage string, not a fraction: `"6.25"` means 6.25%. Supported values run from `"0"` through `"999.999999"`, with up to six decimal places. Dates are real `YYYY-MM-DD` calendar days; an explicit end cannot precede the start.

Without `effectiveEnd` (or with `null`), a new period shortens earlier overlapping periods to the preceding day and stops at the next period's start. With an explicit end, overlapping periods return `422 tax_period_overlap`. The response contains the rate and `meta.createdPeriodId` for the added period.

To remove a period, read its entry in the rate's `periods` array, then DELETE the exact period with that period's own `updatedAt` in `If-Match`, not the rate's timestamp. Removal leaves a gap. Use deletion and a new period to replace a period; there is no period PATCH or close operation.

## Set or clear ship-to tax

```bash
curl "$SHELFCYCLE_API_BASE_URL/tax-assignments?dryRun=true" \
  -X PUT \
  -H "Authorization: Bearer $SHELFCYCLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "shipToAddressId":"33333333-3333-4333-8333-333333333333",
    "taxTypeId":"22222222-2222-4222-8222-222222222222",
    "taxRateId":"44444444-4444-4444-8444-444444444444"
  }'
```

Send all three fields. `taxRateId: null` clears the chosen rate for that ship-to and tax type. These desired-state writes use neither `Idempotency-Key` nor `If-Match`. The response reports `created`, `updated`, `unchanged`, or `cleared`; repeating the identical intended assignment converges to the same state. Use an available tax type and an eligible rate belonging to it; `tax_type_unavailable` or `tax_rate_unavailable` asks you to correct the selection.

POST `/tax-assignments/batch` accepts `{"items":[...]}` with 1 to 50 entries containing unique `clientItemId`, `shipToAddressId`, `taxTypeId`, and nullable `taxRateId`. Do not repeat a ship-to/type pair in one batch. Each item saves independently; results remain in input order under `data.results`. Execution reports `succeeded` or `failed`, while preview reports `ready` or `failed`. Inspect each result rather than assuming the whole batch succeeded. Retry the same intended batch without an idempotency key; completed assignments converge to `unchanged`. Rate limits count submitted items.

## Read, archive, and recover

Lists default to 25 rows and accept `limit` from 1 to 100. Types and rates sort by name; assignments sort by ship-to and tax type. Use `nameQuery` and `includeArchived=true` for catalog discovery; rates also accept `taxTypeId`. Assignments accept `shipToAddressId`, `customerId`, `taxTypeId`, and `taxRateId`. Continue with the identical filters and returned `meta.nextCursor`, keeping the original page size. Exact catalog reads can include archived records.

Type, rate, and period creates require stable `Idempotency-Key` values. An identical retry replays the current resource; reused keys with different intent or deleted replay targets return conflicts rather than creating replacements. Keep `meta.createdPeriodId` with a period create. Missing or outdated change timestamps return `409 stale_record`; read current values before reviewing a fresh change.

Archive through the exact type or rate's `/archive` route with its current `updatedAt` as `If-Match` and an empty body. Type archive also archives its live rates. Repeating archive with the current timestamp returns `changed: false`; archiving is not reversible through an unarchive endpoint.

## How open orders use tax changes

A new, changed, or cleared ship-to assignment, or a disabled/archived type or rate, takes effect on the next save of an open order. A new rate period re-rates existing tax lines. Removing a period or adding a 0% period leaves an existing tax line at its previous percentage; it does not retroactively remove that line. Calculation basis, description, and line flags apply to tax lines created after the change. Completed, Void, and invoiced orders remain unchanged.

Tax lines require sales-order automations enabled for the organization; ask ShelfCycle about that availability. These endpoints maintain your configured tax catalog and assignments rather than determining jurisdictional rates. Verify the selected rate and order behavior as part of your workflow.
