Skip to content

Create City

Create a new city. Requires authentication.

Endpoint

POST /v1/accounts/city/

Authentication

Required

Request Body

Form data (multipart/form-data):

Field Type Required Description
name string Yes City name
country_id integer Yes Country ID

Response

Success (200 OK)

{
  "id": 1,
  "name": "Baku",
  "country_id": 1,
  "country": {
    "id": 1,
    "name": "Azerbaijan",
    "created": "2025-01-15T10:30:00Z"
  },
  "created": "2025-01-15T10:30:00Z"
}

Error Responses

Bad Request (400)

{
  "error": "Name is required"
}

or

{
  "error": "Country ID is required"
}

or

{
  "error": "Invalid country ID"
}

Not Found (404)

{
  "error": "Country not found"
}

Unauthorized (401)

{
  "error": "Missing token on header!"
}

Internal Server Error (500)

{
  "error": "Failed to create city"
}

Example Request

curl -X POST "https://api.luxmart.site/v1/accounts/city/" \
  -H "Authorization: Token your_access_token" \
  -F "name=Baku" \
  -F "country_id=1"

Notes

  • Both name and country_id are required
  • The country must exist and not be deleted
  • The created timestamp is automatically set by the system
  • The id is automatically generated
  • Returns 404 if the specified country does not exist