# エラーコード

Source: https://won.dev/ja/docs/errors

エラーレスポンスはすべて同じJSON形式です。分岐には `message` ではなく `code` を使ってください。`code` は変わりませんが、`message` は変わることがあります。

`hint` には次にとるべき対応が入ります。時間をおけば解決する場合は `retry_after` が設定され、`Retry-After` ヘッダーにも同じ秒数が入ります。サポートに連絡するときは `request_id`（`X-Request-Id` ヘッダーと同じ値）を添えてください。

結果が0件なのはエラーではありません。空のリストとともに `200` が返り、料金はかかりません。失敗したリクエストに料金がかかることはありません。

```json
{
  "error": {
    "code": "insufficient_balance",
    "message": "The balance cannot cover this request.",
    "hint": "Top up in the console. The message says how much is missing.",
    "docs_url": "https://won.dev/docs/errors#insufficient_balance",
    "retry_after": null,
    "request_id": "req_6f1c0d3a9b8e4f2a8c7d5e4b3a2f1e0d"
  }
}
```

| コード | ステータス | 意味 |
| --- | --- | --- |
| [`invalid_input`](#invalid_input) | 400 | A parameter is missing, malformed or out of range. |
| [`unauthorized`](#unauthorized) | 401 | The API key is missing, invalid or revoked. |
| [`insufficient_balance`](#insufficient_balance) | 402 | The balance cannot cover this request. |
| [`budget_exceeded`](#budget_exceeded) | 402 | This request would cost more than `max_cost`, the key's remaining budget or what is left of its daily limit. |
| [`forbidden`](#forbidden) | 403 | This key may not use this product, or it may only read and this changes something. |
| [`sending_suspended`](#sending_suspended) | 403 | Sending is suspended for this sender. |
| [`not_found`](#not_found) | 404 | The resource or endpoint does not exist. |
| [`idempotency_conflict`](#idempotency_conflict) | 409 | This Idempotency-Key was already used with a different request body. |
| [`request_in_progress`](#request_in_progress) | 409 | An identical request is still running. |
| [`invalid_state`](#invalid_state) | 409 | The resource is in a state that does not allow this action. |
| [`no_domains`](#no_domains) | 409 | The sender has no sending domain that can send. |
| [`sender_not_ready`](#sender_not_ready) | 409 | We stopped the sender: it cannot send. |
| [`content_rejected`](#content_rejected) | 422 | The content of an email did not pass the checks. |
| [`daily_limit_reached`](#daily_limit_reached) | 429 | The sender's domains have sent all the emails they may today. |
| [`rate_limited`](#rate_limited) | 429 | Too many requests. |
| [`internal_error`](#internal_error) | 500 | Something went wrong on our side. |
| [`out_of_stock`](#out_of_stock) | 503 | No sending domain that passes our checks is for sale right now. |
| [`upstream_unavailable`](#upstream_unavailable) | 503 | A data source behind this capability is temporarily unavailable. |

## `invalid_input` [#invalid_input]

HTTP 400

**メッセージ（APIの原文）：** A parameter is missing, malformed or out of range.

**対応（APIの原文）：** Check the parameters against the API reference. The message names the field.

## `unauthorized` [#unauthorized]

HTTP 401

**メッセージ（APIの原文）：** The API key is missing, invalid or revoked.

**対応（APIの原文）：** Send `Authorization: Bearer won_live_...` with a key from the console.

## `insufficient_balance` [#insufficient_balance]

HTTP 402

**メッセージ（APIの原文）：** The balance cannot cover this request.

**対応（APIの原文）：** Top up in the console. The message says how much is missing.

## `budget_exceeded` [#budget_exceeded]

HTTP 402

**メッセージ（APIの原文）：** This request would cost more than `max_cost`, the key's remaining budget or what is left of its daily limit.

**対応（APIの原文）：** Raise `max_cost`, raise the key's budget or daily limit in the console, or narrow the request. A daily limit starts over at midnight UTC, which `retry_after` counts down to.

## `forbidden` [#forbidden]

HTTP 403

**メッセージ（APIの原文）：** This key may not use this product, or it may only read and this changes something.

**対応（APIの原文）：** The message says which. Owners and admins set what a key may do on the API keys page of the console, and a connected app gets what was allowed when it was connected.

## `sending_suspended` [#sending_suspended]

HTTP 403

**メッセージ（APIの原文）：** Sending is suspended for this sender.

**対応（APIの原文）：** Too many bounces or complaints, or we stopped it. The message says which, as does `review_note` in `GET /email/senders/{id}`. The account's other senders go on. Write to support to have it looked at.

## `not_found` [#not_found]

HTTP 404

**メッセージ（APIの原文）：** The resource or endpoint does not exist.

**対応（APIの原文）：** Check the ID and the path. An ID starts with its type, such as `co_` for a company or `cmp_` for a campaign, and only works with the endpoints of that type.

## `idempotency_conflict` [#idempotency_conflict]

HTTP 409

**メッセージ（APIの原文）：** This Idempotency-Key was already used with a different request body.

**対応（APIの原文）：** Use a new Idempotency-Key for a different request.

## `request_in_progress` [#request_in_progress]

HTTP 409

**メッセージ（APIの原文）：** An identical request is still running.

**対応（APIの原文）：** Wait `retry_after` seconds, then send it again. Results you already paid for are not charged twice.

## `invalid_state` [#invalid_state]

HTTP 409

**メッセージ（APIの原文）：** The resource is in a state that does not allow this action.

**対応（APIの原文）：** The message names the current state and what is possible from it.

## `no_domains` [#no_domains]

HTTP 409

**メッセージ（APIの原文）：** The sender has no sending domain that can send.

**対応（APIの原文）：** Buy one with `POST /email/domains` (`sender_id`, `count`, `confirm: true`). One that is still setting up is ready within minutes: see `GET /email/domains?sender_id=...`.

## `sender_not_ready` [#sender_not_ready]

HTTP 409

**メッセージ（APIの原文）：** We stopped the sender: it cannot send.

**対応（APIの原文）：** `review_note` in `GET /email/senders/{id}` says why. Write to support to have it looked at.

## `content_rejected` [#content_rejected]

HTTP 422

**メッセージ（APIの原文）：** The content of an email did not pass the checks.

**対応（APIの原文）：** `issues` lists every problem and the step it is in. Fix them and send the request again.

## `daily_limit_reached` [#daily_limit_reached]

HTTP 429

**メッセージ（APIの原文）：** The sender's domains have sent all the emails they may today.

**対応（APIの原文）：** Wait `retry_after` seconds, until midnight UTC, or buy another domain with `POST /email/domains`. Answers to replies are not limited.

## `rate_limited` [#rate_limited]

HTTP 429

**メッセージ（APIの原文）：** Too many requests.

**対応（APIの原文）：** Wait `retry_after` seconds, then retry with the same Idempotency-Key.

## `internal_error` [#internal_error]

HTTP 500

**メッセージ（APIの原文）：** Something went wrong on our side.

**対応（APIの原文）：** Retry with the same Idempotency-Key. You are not charged for failed requests.

## `out_of_stock` [#out_of_stock]

HTTP 503

**メッセージ（APIの原文）：** No sending domain that passes our checks is for sale right now.

**対応（APIの原文）：** Wait `retry_after` seconds, then ask again. Nothing was charged.

## `upstream_unavailable` [#upstream_unavailable]

HTTP 503

**メッセージ（APIの原文）：** A data source behind this capability is temporarily unavailable.

**対応（APIの原文）：** Wait `retry_after` seconds, then retry with the same Idempotency-Key. You are not charged.