Order costs and COGS correction

A line's COGS (cost of goods sold) is calculated when the order is prepared, in the same step that lowers stock. Fenicia spends lots by FIFO or FEFO and stores the per-lot breakdown in items[].cogs. What the lots do not cover comes out of stock without a lot at the product's unitCost. If there is neither a lot nor a unitCost, the row is left with costMissing: true and does not count toward total COGS until you correct it.

A line's original cogs is never modified. Each correction appends a row to items[].cogsAdjustments[] with who made it, when, why, and the previous and new breakdown.

A row with a lot does not accept a free amount

A free amount on a row that spent a lot would make the lots and the COGS stop matching. To correct the cost of a line that has a lot, correct the lot's cost in Lots and valuation: Fenicia recalculates every line that spent it. Only lines without a lot are corrected on this page.

Correct the COGS of a line without a lot

Corrects with an amount the COGS of a line whose row has no lot.

{ "itemIndex": 0, "totalCogs": 420.00, "reason": "Costo capturado de la factura del proveedor" }
200Correction recorded. The original cogs does not change.
{
  "data": {
    "itemIndex": 0,
    "sku": "CAM-ROJO-M",
    "cogs": {
      "unitCostAvg": 0,
      "totalCogs": 0,
      "currency": "MXN",
      "breakdown": [{ "qty": 2, "unitCost": 0, "currency": "MXN", "costMissing": true }]
    },
    "cogsAdjustments": [
      {
        "adjustedBy": "usr_88",
        "adjustedAt": "2026-10-05T18:10:00.000Z",
        "reason": "Costo capturado de la factura del proveedor",
        "previousBreakdown": [{ "qty": 2, "unitCost": 0, "currency": "MXN", "costMissing": true }],
        "newBreakdown": [{ "qty": 2, "unitCost": 210, "currency": "MXN" }],
        "previousTotalCogs": 0,
        "newTotalCogs": 420
      }
    ]
  }
}
400The row has a lot, or the body breaks the schema.
{ "error": { "code": "validation:invalid_input", "message": "El renglón gastó el lote lot_01HZK: corrige el costo del lote" } }
403The orders:costs permission is missing.
{ "error": { "code": "auth:permission_denied", "message": "Permission denied: requires 'orders:costs'" } }
404The order does not exist in your tenant.
{ "error": { "code": "orders:not_found", "message": "Order not found" } }

Returns the line with its original cogs and its cogsAdjustments[] history, now with the new correction. The line's current COGS is the newTotalCogs of the latest correction. If the line has reversals from returns, the correction is also recorded on each affected reversal.

Required permission: orders:costs. Fenicia grants it by default only to the administrator role.

Parameters

orderIdstringrequired

Order ID.

itemIndexnumberrequired

Position of the line within items, 0-based.

totalCogsnumberrequired

Correct total COGS of the line, in the tenant's currency. Greater than or equal to 0. Fenicia spreads it across the row's pieces.

reasonstringrequired

Reason for the correction. It is kept in cogsAdjustments[].

Recalculate COGS by SKU and period

Recalculates a SKU's lines without a lot, over a period, with the product's corrected unitCost.

{ "sku": "CAM-ROJO-M", "from": "2026-09-01", "to": "2026-09-30", "unitCost": 210.00, "reason": "Se capturó el unitCost del producto" }
200Lines recalculated.
{ "data": { "sku": "CAM-ROJO-M", "ordersAffected": 14, "itemsAdjusted": 17 } }
403The orders:costs permission is missing.
{ "error": { "code": "auth:permission_denied", "message": "Permission denied: requires 'orders:costs'" } }

Returns how many orders and lines were corrected. It only changes lines of that SKU and of your tenant that did not spend a lot, and each one receives its row in cogsAdjustments[]. Use it after entering the product's unitCost when there are lines with costMissing.

Required permission: orders:costs

Parameters

skustringrequired

SKU whose lines without a lot are recalculated.

fromstringrequired

Start of the period, ISO 8601 date, over the order's preparation date.

tostringrequired

End of the period, ISO 8601 date.

unitCostnumberrequired

Correct unit cost, in the tenant's currency. Greater than or equal to 0.

reasonstringrequired

Reason for the correction. It is kept in each line's cogsAdjustments[].

Add an additional cost to the order

Records an additional cost of the order, with its category, date and user.

{ "category": "packaging", "description": "Caja de cartón", "amount": 25.00, "currency": "MXN" }
201Cost recorded.
{
  "data": {
    "id": "adc_01J9F",
    "category": "packaging",
    "description": "Caja de cartón",
    "amount": 25,
    "currency": "MXN",
    "source": "manual",
    "appliedAt": "2026-10-05T18:20:00.000Z",
    "createdBy": "usr_88"
  }
}
400The category is not one of the accepted ones, or the amount is negative.
{ "error": { "code": "validation:invalid_input", "message": "Validation failed: category: Invalid enum value" } }

Returns the recorded cost. You can add it at any time. It feeds the profit breakdown in Get an order: one row per category.

There are no categories for shipping, commissions or taxes: they already have their own field on the order and would be counted twice.

Required permission: orders:update

Parameters

orderIdstringrequired

Order ID.

categorystringrequired

Cost category. Accepted values: packaging (packaging and supplies), labor (labor), other (anything else). It is a closed list with no escape value.

descriptionstring

Cost description.

amountnumberrequired

Cost amount. Greater than or equal to 0.

currencystring

3-letter ISO 4217 currency. Default: the tenant's currency.

Remove an additional cost

Deletes an additional cost recorded by hand on an order.

200Cost deleted.
{ "data": { "deleted": true } }
404The order or the cost does not exist in your tenant.
{ "error": { "code": "orders:not_found", "message": "Order not found" } }

Returns the deletion confirmation. A cost with source: "supply" is not deleted here: its supply was already spent from inventory.

Required permission: orders:update

Parameters

orderIdstringrequired

Order ID.

costIdstringrequired

Additional cost ID.

Record a spent supply

Spends a supply from inventory (shipping bag, label) and records it as an additional cost of the order.

{ "sku": "BOLSA-ENVIO-M", "quantity": 1, "category": "packaging" }
201Supply spent and cost recorded.
{
  "data": {
    "id": "adc_01J9G",
    "category": "packaging",
    "amount": 4.5,
    "currency": "MXN",
    "source": "supply",
    "supply": {
      "sku": "BOLSA-ENVIO-M",
      "quantity": 1,
      "breakdown": [{ "lotId": "lot_01J9H", "qty": 1, "unitCost": 4.5, "currency": "MXN" }]
    },
    "appliedAt": "2026-10-05T18:25:00.000Z",
    "createdBy": "usr_88"
  }
}
400The supply does not exist or the quantity exceeds what is available.
{ "error": { "code": "validation:invalid_input", "message": "Validation failed: sku: supply not found" } }

Returns the additional cost with source: "supply" and the breakdown of what was spent. The supply is spent from its lots by FIFO, or from its stock without a lot at unitCost.

Required permission: orders:fulfill

Parameters

orderIdstringrequired

Order ID.

skustringrequired

Supply SKU. It accepts the scanned code already resolved to a SKU.

quantitynumberrequired

Supply pieces. Integer greater than 0.

categorystring

Cost category. Accepted values: packaging, labor, other. Default: packaging.

Returns and COGS

When a return is accepted, Fenicia records the COGS reversal of the returned pieces in items[].cogsReversals[], with the per-lot breakdown, and hands the merchandise to inventory as a reception of type return. Each piece goes back to its original lot when released. See Returns and refunds and Receipts and receiving tray.

Examples

curl -X POST https://api.fenicia.io/orders/65f3a1b2c4d5e6f7a8b9c0d1/cogs-adjustments \
  -H "Authorization: Bearer fkapi_tu_api_key" \
  -H "Content-Type: application/json" \
  -d '{ "itemIndex": 0, "totalCogs": 420.00, "reason": "Costo capturado de la factura del proveedor" }'

Next steps