# /japan_customs/trades/search

`POST /api/japan_customs/trades/search`

Price: 20 credits

Japan Customs export and import records from one e-Stat dataset: value in thousand yen and quantity per HS commodity, partner country, customs office and period

## How to use it

Reads one dataset from the datasets endpoint, so resolve a `dataset_id` there first — this endpoint cannot search across a whole year on its own. Which dimension columns a row carries follows the table the dataset belongs to, and the values_by_* tables drop the dimension their name omits, so a filter on a dimension that table has no column for returns nothing rather than everything. Value is thousand yen; quantity comes in up to two units named by `unit1`/`unit2`, so never compare quantities across rows without checking the unit. `period=year` gives the calendar-year total and `period=all` expands the same rows into thirteen, so a `count` on `all` covers far fewer commodity and country pairs than it looks.

## Parameters

- `access-token` (string, required)

## Request body

- `timeout` (integer) — Max scrapping execution timeout (in seconds) (default: 300; min: 20; max: 1500)
- `dataset` (string, required) — Dataset identifier from the datasets endpoint (examples: "000040368833"; minLength: 12; maxLength: 12; pattern: ^\d{12}$)
- `period` (string) — Which period column to read: the calendar-year total, one named month, or every period as separate rows (default: "year"; one of: "year", "all", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec")
- `hs_codes` (string, nullable) — Keep only rows whose 9-digit HS statistical code starts with one of these, comma-separated. Any prefix length works (examples: "0901", "010121000", "84,85")
- `countries` (string, nullable) — Keep only rows for these Japan Customs 3-digit country codes, comma-separated. Look them up through the countries endpoint (examples: "105", "103,105,304")
- `commodity_codes` (string, nullable) — Keep only rows for these principal-commodity codes, comma-separated (examples: "0", "7")
- `customs_codes` (string, nullable) — Keep only rows for these customs office codes, comma-separated. Only the customs_* tables cut rows by office; the *_by_customs_* tables publish one office per dataset, so there is nothing left to narrow inside one of those files (examples: "100", "300")
- `include_zero_rows` (boolean) — Keep rows whose value is zero for the chosen period. The source stores a zero for every month a commodity and country pair did not trade (default: false)
- `count` (integer, required) — Max number of rows to return (min: 1)

## Response

### 200 — Successful Response

- `@type` (string) (default: "JapanCustomsTrade")
- `record_key` (string, required)
- `dataset_id` (string, required)
- `direction` (string, required) (one of: "export", "import")
- `year` (integer, required)
- `period` (string, required)
- `month` (integer, nullable)
- `hs_code` (string, nullable)
- `country_code` (string, nullable)
- `commodity_code` (string, nullable)
- `customs_code` (string, nullable)
- `transport_mode` (string, nullable) (one of: "air_cargo", "sea_container_cargo")
- `transport_mode_code` (string, nullable)
- `unit1` (string, nullable)
- `unit2` (string, nullable)
- `quantity1` (integer, nullable)
- `quantity2` (integer, nullable)
- `value_thousand_yen` (integer, nullable)

## Errors

### 422 — Validation Error

The request body did not validate

What to do: Check the fields against this schema. A URN with the wrong prefix is the most common cause.

- `detail` (array)
  - `loc` (array, required)
  - `msg` (string, required)
  - `type` (string, required)
  - `input` (any)
  - `ctx` (object)

### 408

The request ran past its time limit

What to do: Raise `timeout` in the request body, up to the maximum this endpoint documents. Lowering `count` or turning off the `with_*` flags also helps, because less work finishes sooner.

### 412

The entity was not found, or a precondition failed

What to do: Retrying will not help: either the entity does not exist, or the input points at a different one.

### 429

Too many requests: a rate limit or a usage window is exhausted

What to do: When the response carries an X-Retry-After header, wait that many seconds and retry: the same number is in the body as `detail.retry_after`, and the limit clears once that window passes. The message in the body names the limit that was hit.

### 500

Something broke on our side

What to do: Retrying will not help. If it keeps happening, send us the X-Request-ID from the response headers.

### 529

Rate limit reached, or the endpoint is overloaded

What to do: Wait at least 30 seconds, then retry.

## Response envelope

Success: Array of objects (may be empty if no results)

Error: Error may coexist with partial results if it occurs mid-execution. Check X-Error header and status code.

Every response carries these headers:

- `X-Error` — Error message text (present only on error)
- `X-Request-ID` — Unique request identifier
- `X-Execution-Time` — Execution time in seconds
- `X-Result-Count` — How many records the body carries. 0 means an empty result, which is a normal answer and not by itself an error. A non-zero count can come back together with X-Error when the failure happened partway through — read this header and X-Error independently.
- `X-Total-Available-Results` — How many records exist for this query, when the endpoint can say. On a `dry_run` request this is the answer and the body is empty. It saturates: the endpoint's documented maximum means 'at least that many', any smaller number is exact.
- `X-Warning` — Present when the request body carried keys this endpoint does not document. They were ignored, so any filter you meant to apply through them did not apply. Check the spelling against this schema and retry.
- `X-Retry-After` — Seconds to wait before retrying. Present only on 429.

