List All Cities
Lists All cities with filtering, search and ordering capabilities
HTTP Request
GET/api/locations/cities
Authorization
Authorization
- Required: Yes
- Permission: Staff with CityPermission or Admin
- Permission Code: 1642
- Authentication: Token-based (Authorization: Token <your_api_key>)
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | 10 | Number of results to return per page |
| offset | integer | 0 | Number of results to skip before returning results |
| search | string | — | Search term to lookup results by`id` and `name` |
| ordering | string | name | Order results by (`id`, `active`, `name`, `state`) |
| country_id | integer | — | Filter cities by country ID |
| country_in | string | — | Filter cities by multiple country IDs (comma-separated: 1,2,3) |
| state_id | integer | — | Filter cities by state ID |
| state_in | string | — | Filter cities by multiple state IDs (comma-separated: 1,2,3) |
| active | boolean | — | Filter by active status |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3url = "https://api.example.com/api/locations/cities"
4headers = {
5 "Authorization": "Token <your_api_key>"
6}
7params = {
8 "limit": 10,
9 "offset": 0,
10 "search": "Los Angeles"
11}
12response = requests.get(url, headers=headers, params=params)
13print(response.json())1curl -X GET "https://api.example.com/api/locations/cities?limit=10&offset=0&search=Los%20Angeles" \
2-H "Authorization: Token <your_api_key>"Response Fields
| Field | Type | Description |
|---|---|---|
| count | Integer | Total number of categories |
| next | String | URL for the next page of results |
| previous | String | URL for the previous page of results |
| results | Array[Object] | Array of City objects |
City Object Structure
| Field | Type | Description |
|---|---|---|
| id | integer | Unique city identifier |
| name | string | City name |
| state | integer | State id |
Sample Response
{
"count": 1119,
"next": "http://127.0.0.1:8000/api/locations/cities?limit=5&offset=5",
"previous": null,
"results": [
{
"id": 527,
"name": "آب بر",
"state": 14
},
{
"id": 261,
"name": "آب پخش",
"state": 7
},
{
"id": 477,
"name": "آبادان",
"state": 13
},
{
"id": 607,
"name": "آباده",
"state": 17
},
{
"id": 608,
"name": "آباده طشک",
"state": 17
}
]
}