# Bulk create account determination rules

Operation ID: `bulkCreateAccountDeterminationRules`

Group: Inventory › Account Determination Rules

[Open in the interactive reference](https://docs.api.lensing.ai/lensing/v1/endpoints/bulkCreateAccountDeterminationRules)

`POST /inventory/account-determination-rules/bulk`

Retry-safe: A write that accepts Idempotency-Key: repeating a request with the same key replays the stored answer instead of executing twice.

Creates multiple account determination rules in one request. The response lists the new rules' ids in the order you sent them. If one rule cannot be created, the request fails and no rules are created.

To create a single rule, use POST inventory/account-determination-rules.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Api-Version` | header | string · v1 | yes | The API version this request targets, named by its public identifier. Required on every request; omitting it, or naming a version this company does not have, is answered with 400. This document describes version `v1`. |
| `Idempotency-Key` | header | string | no | An opaque caller-chosen string (1-255 characters) that makes this request safe to retry. Repeating the same key with an identical request body replays the original response instead of re-executing - but only once that original request succeeded; a failed attempt re-executes on retry. Repeating the key with a different body is answered with 422. A key still in flight is answered with 409 - as is a key whose original request was interrupted before it finished, for a few minutes afterwards, until that attempt is presumed dead. A completed response stays replayable for 24 hours. The key is scoped to the caller, not to the action: reusing it for a different action is answered with 409 or 422 rather than treated independently. On read actions this header is ignored. On write actions that cannot offer the guarantee it is answered with `400 IDEMPOTENCY_NOT_SUPPORTED` rather than silently ignored. |

## Request body

Required, `application/json`: bulkCreateAccountDeterminationRulesInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `accountDeterminationRules` | array<object> | yes | The rules to create. Example: `[{"ruleName":"Finished goods — receipts","priority":10,"matching":{"entityId":"81e8beb1-1415-4012-9012-8138580f43dc","bookId":"b7c19e04-3f52-4a86-9d13-5e8f2a6c0b47","itemCategoryId":"a2f47b91-0c6d-4e38-95b1-7d3e6a428c50","transactionTypeContext":"RECEIPT"},"accounts":{"inventoryAssetAccountId":"1c9e4b07-52da-4f38-9016-3b7e05c2a94f","grniClearingAccountId":"4f0b7d29-6e13-4a85-b2c7-90d1f83e6a52"}}]`. |
| `accountDeterminationRules[].ruleName` | string | yes | The name of the rule. It does not have to be unique. |
| `accountDeterminationRules[].priority` | number | no | The priority of the rule. When two matching rules are equally specific, the one with the lower number is used. |
| `accountDeterminationRules[].isActive` | boolean | no | Whether the rule is active. Defaults to true. |
| `accountDeterminationRules[].matching` | object | yes | The dimensions this rule applies to. If you leave out the item type, item category, location, or transaction type, the rule applies to every value of it. |
| `accountDeterminationRules[].matching.entityId` | string | yes | The unique identifier of the legal entity this rule belongs to. Format: UUID. The rule applies only to inventory documents of this legal entity. See `id` on GET base/entities (entities). |
| `accountDeterminationRules[].matching.bookId` | string | no | The unique identifier of the accounting book this rule applies to. Format: UUID. Required for every rule: leaving it out returns BOOK_REQUIRED. See `id` on GET accounting/books/:id (getBook). |
| `accountDeterminationRules[].matching.itemTypeId` | string | no | The unique identifier of the item type this rule applies to. Format: UUID. See `id` on GET inventory/item-types/:id (getItemType). |
| `accountDeterminationRules[].matching.itemCategoryId` | string | no | The unique identifier of the item category this rule applies to. Format: UUID. The rule also matches items in child categories of this category. See `id` on GET inventory/item-categories/:id (getItemCategory). |
| `accountDeterminationRules[].matching.locationId` | string | no | The unique identifier of the warehouse location this rule applies to. Format: UUID. See `id` on GET inventory/warehouses/:id (getWarehouse). |
| `accountDeterminationRules[].matching.inventoryLocationType` | string | no | The type of location this rule is meant for, such as a warehouse or a store. It is for reference only and does not affect which rule is used. |
| `accountDeterminationRules[].matching.transactionTypeContext` | any | no | The type of transaction this rule applies to, such as 'RECEIPT' or 'SHIPMENT'. 'DEFAULT' applies to every transaction type, the same as leaving the field out. Some journal entries use a different type from their document. For example, a purchase return looks up its goods-returned-not-credited account as 'RECEIPT'. Transfers use 'WAREHOUSE_TRANSFER' or 'INTERCOMPANY_TRANSFER'. 'SALES_INVOICE', 'SALES_CREDIT_MEMO', and 'PURCHASE_INVOICE' are accepted, but no journal entry uses them. One of: `"RECEIPT"`, `"SHIPMENT"`, `"SALES_RETURN"`, `"SALES_INVOICE"`, `"SALES_CREDIT_MEMO"`, `"PURCHASE_RETURN"`, `"PURCHASE_INVOICE"`, `"PURCHASE_CREDIT_MEMO"`, `"INVENTORY_INCREASE"`, `"INVENTORY_DECREASE"`, `"INVENTORY_REVALUATION"`, `"WAREHOUSE_TRANSFER"`, `"INTERCOMPANY_TRANSFER"`, `"DEFAULT"`. |
| `accountDeterminationRules[].accounts` | object | no | The general ledger accounts that journal entries use when this rule matches. |
| `accountDeterminationRules[].accounts.inventoryAssetAccountId` | string | no | The unique identifier of the balance sheet account for inventory value. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.cogsAccountId` | string | no | The unique identifier of the cost of goods sold account. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.cogsClearingAccountId` | string | no | The unique identifier of the cost of goods sold clearing account. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.deferredCogsAccountId` | string | no | The unique identifier of the deferred cost of goods sold account. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.salesRevenueAccountId` | string | no | The unique identifier of the sales revenue account. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.salesReturnAccountId` | string | no | The unique identifier of the sales return account. Format: UUID. A reason-code override in `reasonCodeOverrides` can replace it. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.salesStockInTransitAccountId` | string | no | The unique identifier of the sales stock-in-transit account. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.grniClearingAccountId` | string | no | The unique identifier of the goods-received-not-invoiced clearing account, for inventory items. Format: UUID. A receipt uses it to hold the value of goods received until the vendor bill arrives. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.grncClearingAccountId` | string | no | The unique identifier of the goods-returned-not-credited clearing account. Format: UUID. A purchase return uses it to hold the value of goods returned to a vendor until the vendor's credit arrives. Set it on a rule for 'RECEIPT', not 'PURCHASE_RETURN', because purchase returns look it up with 'RECEIPT'. A reason-code override in `reasonCodeOverrides` can replace it. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.servicesReceivedNotInvoicedAccountId` | string | no | The unique identifier of the clearing account for services received but not yet invoiced, and for non-inventory items. Format: UUID. A receipt uses it to hold the value of services and non-inventory items received until the vendor bill arrives. For a receipt line with no item, it comes from the general rule for the legal entity and accounting book. If there are several general rules, the one with the lowest priority number is used, whatever its transaction type. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.expenseAccountId` | string | no | The unique identifier of the expense account for non-inventory items. Format: UUID. An account on a receipt line for a service or expense replaces it for that line. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.purchasePriceVarianceAccountId` | string | no | The unique identifier of the purchase price variance account, under standard costing. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.inventoryAdjustmentGainAccountId` | string | no | The unique identifier of the account for the value of stock added by an inventory increase, including one created from an inventory count. Format: UUID. Two things can replace it: a reason-code override in `reasonCodeOverrides`, or an offset account on an inventory increase created by manufacturing. When both apply, the offset account is used. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.inventoryAdjustmentLossAccountId` | string | no | The unique identifier of the account for the value of stock removed by an inventory decrease, including one created from an inventory count. Format: UUID. Two things can replace it: a reason-code override in `reasonCodeOverrides`, or an offset account on an inventory decrease created by manufacturing. When both apply, the offset account is used. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.revaluationGainAccountId` | string | no | The unique identifier of the account for gains from inventory revaluation. Format: UUID. When an inventory revaluation's `costingValuationType` is 'directCostCapitalisation', its `capitalisationExpenseAccountId` replaces it. See `costingValuationType` on GET inventory/inventory-revaluations/:id (getInventoryRevaluation). See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.revaluationLossAccountId` | string | no | The unique identifier of the account for losses from inventory revaluation. Format: UUID. When an inventory revaluation's `costingValuationType` is 'directCostCapitalisation', its `capitalisationExpenseAccountId` replaces it. See `costingValuationType` on GET inventory/inventory-revaluations/:id (getInventoryRevaluation). See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.soldQuantitiesRevaluationAccountId` | string | no | The unique identifier of the account for the revaluation of quantities already sold. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.purchaseReturnVarianceGainAccountId` | string | no | The unique identifier of the account for gains on purchase returns. Format: UUID. A purchase return uses it when the goods returned are worth more than their original cost. A reason-code override in `reasonCodeOverrides` can replace it. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.purchaseReturnVarianceLossAccountId` | string | no | The unique identifier of the account for losses on purchase returns. Format: UUID. A purchase return uses it when the goods returned are worth less than their original cost. A reason-code override in `reasonCodeOverrides` can replace it. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].accounts.fxRateDiffAccountId` | string | no | The unique identifier of the account for exchange rate differences between the receipt and the vendor bill. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].reasonCodeOverrides` | array<object> | no | The rule's reason-code overrides. When a document line has one of these reason codes, the override's account replaces the rule account named by `parentAccountType`. An inventory increase or decrease created by manufacturing that has its own offset account uses that account instead of an override. Each combination of `reasonCodeId` and `parentAccountType` can appear only once on a rule. |
| `accountDeterminationRules[].reasonCodeOverrides[].reasonCodeId` | string | yes | The unique identifier of the reason code that triggers this override. Format: UUID. See `id` on GET inventory/reason-codes/:id (getReasonCode). |
| `accountDeterminationRules[].reasonCodeOverrides[].accountId` | string | yes | The unique identifier of the account the journal entry uses instead of the rule's account. Format: UUID. See `id` on GET accounting/accounts/:id (getAccount). |
| `accountDeterminationRules[].reasonCodeOverrides[].parentAccountType` | any | yes | Which rule account this override replaces. Only six of the twenty accounts can be overridden. One of: `"inventoryAdjustmentGainAccount"`, `"inventoryAdjustmentLossAccount"`, `"salesReturnAccount"`, `"purchaseReturnVarianceGainAccount"`, `"purchaseReturnVarianceLossAccount"`, `"grncClearingAccount"`. |

```json
{
  "accountDeterminationRules": [
    {
      "ruleName": "Finished goods — receipts",
      "priority": 10,
      "matching": {
        "entityId": "81e8beb1-1415-4012-9012-8138580f43dc",
        "bookId": "b7c19e04-3f52-4a86-9d13-5e8f2a6c0b47",
        "itemCategoryId": "a2f47b91-0c6d-4e38-95b1-7d3e6a428c50",
        "transactionTypeContext": "RECEIPT"
      },
      "accounts": {
        "inventoryAssetAccountId": "1c9e4b07-52da-4f38-9016-3b7e05c2a94f",
        "grniClearingAccountId": "4f0b7d29-6e13-4a85-b2c7-90d1f83e6a52"
      }
    }
  ]
}
```

## Response

`200` Success

Under `data` (bulkCreateAccountDeterminationRulesOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `created` | array<object> | yes | The created rules, in the order you sent them. Example: `[{"id":"8d3f1a60-4c27-4e95-b013-6f2a89d47c5e"}]`. |
| `created[].id` | string | yes | The unique identifier for the created rule. Format: UUID. |

```json
{
  "data": {
    "created": [
      {
        "id": "8d3f1a60-4c27-4e95-b013-6f2a89d47c5e"
      }
    ]
  },
  "diagnostics": [
    {
      "code": "<code>",
      "message": "<message>",
      "severity": "error",
      "path": [
        "<path>"
      ],
      "details": "<details>"
    }
  ]
}
```

## Response headers

- `Idempotency-Replayed` — Present and `true` only when this response replays a previously stored one for the same Idempotency-Key, rather than reflecting a live execution. Absent on a live response - never sent as `false`.

## Errors

| Code | Status |
| --- | --- |
| `REFERENCE_NOT_FOUND` | 400 |
| `BOOK_REQUIRED` | 400 |
| `DUPLICATE_RULE_TUPLE` | 400 |
| `UNKNOWN_PARENT_ACCOUNT_TYPE` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: REFERENCE_NOT_FOUND, BOOK_REQUIRED, DUPLICATE_RULE_TUPLE, UNKNOWN_PARENT_ACCOUNT_TYPE
- `401` — The request carries no valid access token.
- `403` — Not authorized
- `404` — Not found
- `409` — The Idempotency-Key is still being processed by another request.
- `422` — The Idempotency-Key was already used with a different request payload.
- `429` — Too many requests from this client address. The response has no body and no `Retry-After` header.
- `500` — Internal server error
