# Repack template imports

Import reviewed Repack templates with exact products, packaging, operating options, and per-item results.

Canonical HTML: https://developer.shelfcycle.com/guides/repack-templates

Import reusable repacking setups with exact products, output packaging, recurring costs, operating options, and process steps.

## Access and preparation

Use `POST /repack-templates/batch` with `repack-templates:write`, current Work Order update permission, and Work Orders enabled for the organization and acting person. In `GET /me`, `effectiveCapabilities.repackTemplates.create` reports scope and permission availability, while `repackTemplates.workOrderV2Eligible` also includes Work Order availability. `writeReadiness.repackTemplates.create` includes that availability too. The import checks it again, including for previews.

Products and packaging must already exist in the organization. `productCode` and `packagingName` match exactly and case-insensitively. Packaging choices follow those available for the input's base unit in the Repack editor. For a fixed-package output product, send its catalog packaging name and capacity exactly.

## Preview a template batch

Send 1 to 50 items with unique, stable `clientItemId` values and distinct trimmed template names. Replace the example codes, packaging name, capacity, and ledger account UUID with your reviewed values.

```bash
curl "$SHELFCYCLE_API_BASE_URL/repack-templates/batch?dryRun=true" \
  -X POST \
  -H "Authorization: Bearer $SHELFCYCLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      {
        "clientItemId": "repack-001",
        "payload": {
          "name": "Northstar bulk to drums",
          "description": "Reviewed drum repacking setup",
          "inputs": [{ "productCode": "SOLVENT-BULK", "isPackaging": false }],
          "outputs": [{ "productCode": "SOLVENT-DRUM", "packagingName": "Drum", "capacityUOM": 55, "kind": "PRODUCT" }],
          "tolerance": 1,
          "allowPartialPackage": false,
          "allowCrossFamilyRepack": false,
          "keepLotIdentity": true,
          "costs":[{
            "description":"Fill charge",
            "ledgerAccountId":"11111111-1111-4111-8111-111111111111",
            "amount":"0.125",
            "currencyCode":"USD",
            "basis":"PER_INPUT_LB",
            "split":{"scope":"one","outputIndex":0}
          }]
        }
      }
    ]
  }'
```

The preview returns ordered `ready` or `failed` outcomes without saving templates. It does not require an `Idempotency-Key`.

## Describe the setup

Each payload requires `name`, at least one `inputs` entry, and at least one `outputs` entry. Inputs use `productCode` and optional `isPackaging`; include at least one non-packaging input. Each output requires `productCode`, `packagingName`, positive numeric `capacityUOM`, and `kind` (`PRODUCT` or `PACKAGE`).

Optional settings are `tolerance` from 0 to 100, `allowPartialPackage`, `allowCrossFamilyRepack`, and `keepLotIdentity`. Optional `processSteps` use `name` and `attrs` with `key`/`value` pairs, as in [Formula imports](/guides/formulas).

Each template supports up to 100 product-code entries across inputs and outputs, counting repeats. The name after trimming and the optional description each support up to 2400 UTF-8 bytes. The complete request supports up to 2 MB.

## Include recurring costs

Optional `costs` use `description`, `ledgerAccountId`, exact nonnegative `amount` in cents, required supported `currencyCode`, `basis`, and `split`; optional nullable `supplierId` supplies a default supplier. Prefer decimal strings for fractional cents. Repack basis is `PER_INPUT_LB`, per pound of material input, or `FIXED`, once per work order; Repack does not use Formula's `PER_BATCH` basis.

Allocation uses zero-based positions in this payload's `outputs`, including `PACKAGE` rows. Repeated product and container targets remain separate positions. Use `scope: "one"` with `outputIndex`, `scope: "all"` with an automatic method, or `scope: "chosen"` with at least two distinct `outputIndexes` and a method. Custom `BY_RATIO_SPLIT` weights use those output-index strings as keys. See [Formula cost allocation](/guides/formulas) for the shared automatic methods and custom-weight example.

Omitting `costs` or sending `[]` creates no costs. Malformed costs or unavailable output positions fail only that template. Account, default supplier, and exchange-rate eligibility are checked when a work order uses the template; importing saves defaults rather than creating a work order. Keep costs unchanged on an identical retry. This route creates templates rather than updating costs on existing ones.

## Save and resume

Execute the reviewed body without `dryRun=true` and with a stable `Idempotency-Key`. Results stay in input order and identify each `clientItemId`, with `succeeded` or `failed` status. Saved items return their template ID, name, number, and `resultAction: "created"`.

Invalid content, unknown or ambiguous identifiers, archived products, and existing template names fail the affected item without undoing successful templates. Missing or repeated item IDs, missing names, and duplicate trimmed names within the batch reject the complete request before saves.

After an interruption, repeat the identical body, item order, item IDs, and key. Recorded outcomes return and only pending items continue; a completed retry reports `idempotencyStatus: "replayed"`. Submit corrected failed items under a new stable key without already successful items. `X-RateLimit-Cost` reports submitted item count.

This saves templates, not work orders or inventory movements. Use the saved templates in the appropriate ShelfCycle work-order workflow.
