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.
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.
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.
429 with a Retry-After header (seconds).
Every response has X-RateLimit-Limit and X-RateLimit-Remaining.401: missing, wrong or revoked key. 403: the store is not on the Pro plan.
422: a parameter is wrong; the body's error says which.GET /itemsTracked 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/cogsCOGS 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/valuationInventory 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-changesEvery cost change in a range (from, to, page; 100 per page).
GET /reports/marginMargin by product or variant: from, to, group (product or
variant), include_test.
GET /reports/stock-adjustmentsStock changes made in Shopify without a CostTrail record (shrink, damage, counts), per item and day:
from, to, page (250 per page).