CostTrail API

Version 1 · read-only · Pro plan

The CostTrail API lets your other tools (a spreadsheet, a BI dashboard, an ERP) read your store's costs, cost history and reports. It returns the same numbers as CostTrail in the Shopify admin. It can't change anything.

Keys

The store owner creates a key in CostTrail → Settings → API keys. The key is shown once: keep it somewhere safe, like a password. Revoke a key there when a tool no longer needs it. Keys stop working while the store is not on the Pro plan.

Requests

Base URL: https://costtrail.longestvision.com/api/v1. Send the key in the Authorization header:

curl -H "Authorization: Bearer ct_your_key" https://costtrail.longestvision.com/api/v1/items

Responses are JSON. Amounts are decimal strings in the store currency with 6 decimals; dates are shop-local days (YYYY-MM-DD) and times are ISO 8601.

Limits and errors

Endpoints

GET /items

Tracked items with their unsold stock and costs, 50 per page. Parameters: page, search (SKU or title), status (unknown, opening, costed). Each item: id, sku, title, unsold, average_cost (null when unknown), cost_status, shopify_cost. meta has page, last_page, total.

GET /items/{id}

One item with its cost history (newest first): each event's type (opening balance, receipt, charge allocation, manual adjustment, write-back, undo), effective_at, recorded_at, quantities, avg_before and avg_after, COGS adjustment and revaluation, and the receipt it belongs to.

GET /reports/cogs

COGS by period. Parameters: from, to (days, at most 400 apart; default this month), grouping (day, week, month, total), include_test (1 to include test orders). Each period: units sold and returned, snapshot COGS, COGS adjustments, COGS, return cost variance, revaluations, stock adjustments and the journal lines.

GET /reports/valuation

Inventory value at the end of a day: date (default today). Each item's unsold units, average cost and value, as recorded by then.

GET /reports/cost-changes

Every cost change in a range (from, to, page; 100 per page).

GET /reports/margin

Margin by product or variant: from, to, group (product or variant), include_test.

GET /reports/stock-adjustments

Stock changes made in Shopify without a CostTrail record (shrink, damage, counts), per item and day: from, to, page (250 per page).