> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce-openapis/admin/cities.md).

# Cities

Administrative endpoints for **cities** — the city records used as the second level of the address hierarchy (Country → City → Township → District).

A city belongs to a single country and consists of a display name, an active/inactive status, an optional sort priority, an optional post/zip code, and optional multilingual translations of the name.

### Core Capabilities

**1. City Listing & Filtering**

* Retrieve a paginated list of all cities (active and inactive), ordered by priority ascending, then name ascending.
* Filter by country, country code, name (exact or starts-with prefix), presence of a retail store, retail store active status, or retail store type.
* Order results with the `sort` parameter.

**2. City Lifecycle Management**

* Create a city under a country with a unique name within that country.
* Fully or partially update an existing city, including its translations.
* Deactivate a city (soft delete — sets `is_active` to `false`; the record is not removed).

**3. Multilingual Names**

* Store translated names under the `translations` field, keyed by language code.

### City Fields

| Field          | Type                   | Description                                                                                                                  |
| -------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `pk`           | integer                | The unique identifier of the city. Assigned by the server; read-only.                                                        |
| `is_active`    | boolean                | Whether the city is active.                                                                                                  |
| `name`         | string (max 128 chars) | The display name of the city. Required on create and full update.                                                            |
| `country`      | integer                | The identifier of the country this city belongs to. Required on create and full update.                                      |
| `priority`     | integer or `null`      | The sort priority of the city. Lower values appear first; `null` sorts after all numbered priorities. Optional.              |
| `postcode`     | string or `null`       | The post/zip code associated with the city. Optional.                                                                        |
| `translations` | object or `null`       | A mapping of language codes to translated field values. Example: `{"tr": {"name": "İstanbul"}}`. Optional; defaults to `{}`. |

### Filtering & Ordering

| Parameter                | Match                   | Notes                                                                                                                               |
| ------------------------ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `name`                   | Exact                   | Case-sensitive exact match on the city name.                                                                                        |
| `name_startswith`        | Case-insensitive prefix | `?name_startswith=ist` matches `Istanbul`.                                                                                          |
| `country`                | Exact (integer)         | Keeps only cities belonging to the given country id.                                                                                |
| `country__code`          | Exact, case-insensitive | `?country__code=tr` and `?country__code=TR` return the same cities.                                                                 |
| `retailstore__isnull`    | Boolean                 | `false` keeps only cities that have at least one retail store (via their townships); `true` keeps only cities with no retail store. |
| `retailstore__is_active` | Boolean                 | Filters by the `is_active` status of retail stores linked through townships.                                                        |
| `store_type`             | Exact, case-sensitive   | Keeps only cities whose retail stores (via townships) have the given store type name.                                               |

Results are ordered by `priority` ascending first, then `name` ascending. Use the `sort` query parameter to change the order; prefix with `-` for descending (e.g. `?sort=-pk`).

### Validation Rules

* `name` and `country` are required on create and full update.
* The combination of `country` and `name` must be unique **at the application layer** (there is no database-level unique constraint). A duplicate is rejected with `406 Not Acceptable` carrying `{"non_field_errors": "<message>", "error_code": "<code>"}`. This check applies to **create** (`POST`) and **update** (`PUT`/`PATCH`).

### Soft Delete

Calling `DELETE /cities/{id}/` does **not** remove the record from the database. It sets `is_active` to `false`. The record can be reactivated at any time with `PATCH /cities/{id}/` sending `{"is_active": true}`.

### Dynamic Settings & Environment Variables

No dynamic settings (`dj_dynamic_settings`) are read directly by the city endpoints. Listing, create, update, and deactivate operations behave identically regardless of management panel configuration.

The `DEFAULT_COUNTRY_CODE` dynamic setting — registered in `omnishop/address/settings/conf.py` — identifies which country is used as the default in address forms and checkout flows, but it is consumed by the address and checkout services, not by these administrative endpoints.

**Environment variables:** No environment variables are read directly by these endpoints.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://apidocs.akinon.com/commerce-openapis/admin/cities.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
