# Import COGS (cost of goods) for many orders: JSON rows or a CSV file

> Eto API reference for `POST /api/v1/costs/import`. Base URL `https://eto.tools/api/v1/`. Authenticate with the `X-Eto-API-Key` header.

Part of the [Eto API reference](https://eto.tools/dev/docs/). The full reference in one file is at [llms-full.txt](https://eto.tools/dev/docs/llms-full.txt); the machine-readable schema is at [openapi.json](https://eto.tools/dev/docs/openapi.json).

## POST /api/v1/costs/import

Import COGS (cost of goods) for many orders: JSON rows or a CSV file

- Operation ID: `costs_import`
- Slug: `costs-import`
- Category: Orders
- Authentication: API key only. Reads or writes data Eto holds for your own account.
- HTML: https://eto.tools/dev/docs/#ep-costs-import
- Markdown: https://eto.tools/dev/docs/orders/costs-import.md

Bulk-load what your orders cost you, from a bot, a supplier's spreadsheet or an agent. Up to 5,000 rows per call, across all your connected stores. Same rules as Import COGS on the Orders page. Three ways to send it: (1) JSON `{"rows": [...]}`; (2) JSON `{"csv": "<the file as text>"}` (easiest from an agent or MCP); (3) the CSV file itself with `Content-Type: text/csv`, or as a form upload in a field named `file` (options then go in the query string or form fields). A ROW names what it costs: `receipt_id` (the Etsy order number) costs the WHOLE order (the total goes on its first line, every other line is set to 0), or `transaction_id` costs one order line. Add `shop_id` to only match in one store. The amount: `cost_cents` (integer cents, the whole line or order, NOT per unit), or `cost` as money ("12.50", "£12.50", "1.234,56"), or `unit_costs_cents` (per-unit list in cents) or `unit_costs` (the same list as money, ["4.50", "5.20"] or "4.50;5.20"), both for transaction rows only; `cost_cents: null` clears. Rows for the same order or line ADD UP, so a supplier file with one row per item works as is. CURRENCY: amounts are in each order's own currency unless the row says otherwise. A currency written in the cost ("6,50 €", "6.50 EUR", "US$6.50") or a `currency` field (per row, or for the whole call; the row wins) is converted into the order's currency at Eto's daily rate, and the rates used come back in `fx`. A bare "$" is the order's own dollar (CAD on a CAD order) and USD otherwise. "¥" and "kr" are shared by several currencies: on an order in none of them the row is listed in `unmatched` with reason `currency_ambiguous`, and you resend it with the code ("650 JPY"). A cost and a `currency` field that disagree, or an unknown code, is a malformed row. CSV columns are matched by name, case-insensitive: order number / order / receipt_id, transaction_id, shop_id, cost / cogs / item cost / total cost, cost_cents, unit_costs ("4.50;5.20"), currency. A row with an empty cost cell is skipped (counted in `skipped_blank`), never cleared. The CSV from GET /api/v1/costs?format=csv imports back unchanged. TWO KINDS OF PROBLEM: a malformed row (no id, a negative or non-numeric cost, an order sent both whole and line by line) answers 400 VALIDATION_FAILED with every problem in `error.fields` (`index`, and `line` for a CSV) and saves NOTHING. A row whose order Eto does not have yet (not synced, or not in your stores) is listed in `unmatched` with a `reason` and the other rows ARE saved: run orders_sync and send just those rows again. `dry_run: true` does every check and returns the full preview without saving. Every touched line is in `changes` with `before` and `after`, so any import can be undone by importing the `before` values. Zero Etsy calls.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `rows` | body | `array` | no | [{"receipt_id": 3456789012, "cost_cents": 1250}] or [{"transaction_id": 4123456789, "cost": "9.00"}] |
| `csv` | body | `string` | no | The CSV file as text, instead of rows |
| `currency` | body | `string` | no | 3-letter code of the amounts, when not each order's own currency (a row, or a currency written in its cost, wins) |
| `shop_id` | body | `string` | no | Only match orders in this connected store |
| `dry_run` | body | `boolean` | no | true previews without saving (default false) |

### Request

```bash
curl -X POST -H "X-Eto-API-Key: eto_your_key" -H "Content-Type: application/json" -d '{"rows": [{"receipt_id": 3456789012, "cost_cents": 1250}, {"receipt_id": 3456789013, "cost": "8.40"}], "dry_run": true}' "https://eto.tools/api/v1/costs/import"
```

```python
import requests

url = "https://eto.tools/api/v1/costs/import"
headers = {"X-Eto-API-Key": "eto_your_key"}
payload = {
    "rows": [
        {
            "receipt_id": 3456789012,
            "cost_cents": 1250
        },
        {
            "receipt_id": 3456789013,
            "cost": "8.40"
        }
    ],
    "dry_run": True
}

response = requests.post(url, headers=headers, json=payload, timeout=120)
response.raise_for_status()
print(response.json())
```

```javascript
const url = "https://eto.tools/api/v1/costs/import";
const payload = {
  "rows": [
    {
      "receipt_id": 3456789012,
      "cost_cents": 1250
    },
    {
      "receipt_id": 3456789013,
      "cost": "8.40"
    }
  ],
  "dry_run": true
};

const response = await fetch(url, {
  method: "POST",
  body: JSON.stringify(payload),
  headers: {
    "X-Eto-API-Key": "eto_your_key",
    "Content-Type": "application/json",
  },
});
if (!response.ok) throw new Error(`Eto API ${response.status}`);
const data = await response.json();
```

### Response

```json
{
  "dry_run": true,
  "saved": false,
  "rows_received": 2,
  "matched": 1,
  "lines_changed": 2,
  "lines_unchanged": 0,
  "unmatched": [
    {"rows": [1], "receipt_id": 3456789013, "reason": "order_not_found",
     "message": "No order with this number in your connected stores. Sync orders and send the row again."}
  ],
  "changes": [
    {"shop_id": "12345678", "receipt_id": 3456789012, "transaction_id": 4123456789, "currency": "GBP",
     "before": {"item_cost_cents": null, "unit_costs_cents": null},
     "after": {"item_cost_cents": 1250, "unit_costs_cents": null, "cost_cents": 1250, "configured": true},
     "changed": true},
    {"shop_id": "12345678", "receipt_id": 3456789012, "transaction_id": 4123456790, "currency": "GBP",
     "before": {"item_cost_cents": 300, "unit_costs_cents": null},
     "after": {"item_cost_cents": 0, "unit_costs_cents": null, "cost_cents": 0, "configured": true},
     "changed": true}
  ],
  "fx": null
}
```

### Errors

Failures answer with the shared error body described in the Errors section: `{"error": {"code", "status", "message", "hint", "docs"}}`. Branch on `code`, not on the message.
