# Set or clear COGS (cost of goods) for one order

> Eto API reference for `PUT /api/v1/orders/{shop_id}/{receipt_id}/costs`. 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).

## PUT /api/v1/orders/{shop_id}/{receipt_id}/costs

Set or clear COGS (cost of goods) for one order

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

Set what one order cost YOU, line by line or as a whole. Same URL as order_costs (GET). Send EITHER `lines` OR `cogs_cents`, not both. `lines: [{"transaction_id": 4123456789, "cost_cents": 900}]` costs single lines: `cost_cents` is the whole line (all units together, NOT per unit), `unit_costs_cents: [450, 520]` gives one cost per unit instead (the line costs their sum), `cost: "9.00"` is the same as cost_cents written as money, `unit_costs: ["4.50", "5.20"]` is the per-unit list written as money, and `cost_cents: null` clears a line back to "not configured". `cost: "9.00"` also works for the whole order. Lines you do not list are left as they are. `cogs_cents: 970` costs the WHOLE order: the total goes on its first line and every other line is set to 0, so the order reads as fully costed; `cogs_cents: null` clears every line. Amounts are integer cents in the order's currency; send `currency: "USD"` when your figure is in another currency and Eto converts it at its daily rate (the rate used comes back in `fx`). A currency written in a money string is read too: "6,50 €", "6.50 EUR" and "US$6.50" are converted. A bare "$" means the order's own dollar (CAD on a CAD order) and USD otherwise; "¥" and "kr" are shared by several currencies, so on an order in none of them write the code ("650 JPY"). `dry_run: true` checks and previews without saving. The response lists every touched line in `changes` with its `before` and `after` values (send the `before` values back to undo), `lines_changed`/`lines_unchanged`, and `order`: the order's costs as order_costs returns them, after the change. A transaction_id that is not on this order answers 400 VALIDATION_FAILED and saves nothing. Profit figures (order_detail.profit, finance) pick the new cost up within a minute. Zero Etsy calls.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `shop_id` | path | `integer` | yes | Connected shop id |
| `receipt_id` | path | `integer` | yes | Etsy receipt id, from orders_list |
| `lines` | body | `array` | no | [{"transaction_id": 4123456789, "cost_cents": 900 \| null}] or with "unit_costs_cents": [450, 520], "unit_costs": ["4.50", "5.20"] or "cost": "9.00" |
| `cogs_cents` | body | `integer` | no | The whole order's cost in cents (first line gets it, the rest 0). null clears the order. Nullable. |
| `cost` | body | `string` | no | The whole order's cost written as money ("12.50", "6,50 €"), instead of cogs_cents Nullable. |
| `currency` | body | `string` | no | 3-letter code of the amounts you send, when not the order's own currency |
| `dry_run` | body | `boolean` | no | true previews without saving (default false) |

### Request

```bash
curl -X PUT -H "X-Eto-API-Key: eto_your_key" -H "Content-Type: application/json" -d '{"lines": [{"transaction_id": 4123456789, "cost_cents": 900}, {"transaction_id": 4123456790, "unit_costs_cents": [450, 520]}]}' "https://eto.tools/api/v1/orders/12345678/3456789012/costs"
```

```python
import requests

url = "https://eto.tools/api/v1/orders/12345678/3456789012/costs"
headers = {"X-Eto-API-Key": "eto_your_key"}
payload = {
    "lines": [
        {
            "transaction_id": 4123456789,
            "cost_cents": 900
        },
        {
            "transaction_id": 4123456790,
            "unit_costs_cents": [
                450,
                520
            ]
        }
    ]
}

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

```javascript
const url = "https://eto.tools/api/v1/orders/12345678/3456789012/costs";
const payload = {
  "lines": [
    {
      "transaction_id": 4123456789,
      "cost_cents": 900
    },
    {
      "transaction_id": 4123456790,
      "unit_costs_cents": [
        450,
        520
      ]
    }
  ]
};

const response = await fetch(url, {
  method: "PUT",
  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": false,
  "saved": true,
  "rows_received": 2,
  "matched": 2,
  "lines_changed": 2,
  "lines_unchanged": 0,
  "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": 900, "unit_costs_cents": null, "cost_cents": 900, "configured": true},
      "changed": true
    }
  ],
  "fx": null,
  "order": {"receipt_id": 3456789012, "cogs_cents": 1870, "lines_configured": 2, "lines_total": 2,
            "has_cogs_configured": true, "lines": ["...same shape as order_costs..."]}
}
```

### 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.
