Create Account Rule
POST/api/product-account-rules
Create an account rule that sets product GL accounts for every product matching its conditions.
accounting:writeGrant this scope to your token under Settings → Developer → Personal Access Tokens.
How a product's account is chosen. For each account type, a product's own account override wins; otherwise the first active, non-archived rule (lowest position) whose conditions all match sets it; otherwise the company default applies. Sales channel, sub-channel and warehouse accounts still apply below this product level, and a rule with channel_accounts_take_priority: true steps aside for a channel that sets its own Sales, COGS or Discount account.
Authentication: Requires Bearer token with the accounting:write scope and the manage-accounting-settings permission.
Request body fields:
name(string, max 120) — unique among non-archived rules. Required.is_active(boolean, optional, defaulttrue) — inactive rules are kept in the order but never match.channel_accounts_take_priority(boolean, optional, defaultfalse) — whentrue, a sales channel or sub-channel that sets its own Sales, COGS or Discount account wins over this rule for orders on that channel. Has no effect on the other account types.conditions(object) required — every non-empty group must match (AND); values inside one group are alternatives (OR). At least one group must be set.conditions.category_ids(array of integers) — product category ids.conditions.include_subcategories(boolean, defaulttrue) — also match products in sub-categories of the listed categories.conditions.category_scope(string,primary|any, defaultprimary) —primarymatches on the product's primary category only;anymatches any category the product is in.conditions.brand_ids(array of integers) — brand ids.conditions.supplier_ids(array of integers) — matched against the product's default supplier.conditions.product_types(array of strings) — one or more of: standard, bundle, kit, matrix, blemished, manufactured.conditions.tag_ids(array of integers) — product tag ids.conditions.sku_prefixes(array of strings, max 5 entries, each max 40 characters) — case-insensitive "SKU starts with".
accounts(object) required — the nominal code id to use per account type; sendnull(or omit the key) to leave that type to lower layers. At least one account must be set. Archived nominal codes are rejected.accounts.sales(integer|null) — Sales (revenue) account.accounts.cogs(integer|null) — Cost of goods sold account.accounts.inventory(integer|null) — Inventory asset account.accounts.inventory_in_transit(integer|null) — Inventory in transit account.accounts.accrued_purchases(integer|null) — Accrued purchases (liability) account.accounts.discount(integer|null) — Discount account.
position(integer ≥ 1, optional) — place the rule at this position (1 = evaluated first). When omitted on create, the rule is inserted above the first rule with fewer condition groups (more specific rules first), otherwise at the end.confirm_type_mismatch(boolean, optional) — settrueto accept an account whose type does not fit its slot (for example an expense account as the Sales account). Without it such a request returns 422 withcode: type_mismatch.
Returns 201 with the created rule. Every change to the rule set queues a background run that re-applies the rules to the whole catalog. Its id is returned as tracked_job_id; poll GET /api/tracked-job-logs/{trackedJobLog} to follow it. A newer change supersedes a run that is still queued or running.
Request
Responses
- 201
- 401
- 403
- 422
- 429
Created
Response Headers
Unauthenticated — the bearer token is missing, revoked, expired, or malformed. Never retry automatically; fix the credential. See the Errors guide.
Forbidden — the token lacks a required scope, the endpoint is not available to API tokens, or the user behind the token lacks the permission. A human must adjust the token scopes or user permissions; do not retry.
Unprocessable Entity
Response Headers
Rate limited — platform limit is 1,000 requests/min; individual tokens may carry lower limits. Honor the Retry-After header before retrying. See the Rate Limits guide.