Skip to main content

Overview

The Countries API allows you to manage country (País) records in the system. Countries are the top level of the geographic hierarchy: Country → State → City.

Model Structure

Table: paises Primary Key: id_pais

Fields

id_pais
integer
Unique identifier for the country
nombre
string
required
Country name (max 80 characters, must be unique)
created_at
timestamp
Record creation timestamp
updated_at
timestamp
Record last update timestamp

Relationships

departamentos
array
Collection of states/departments belonging to this country

List All Countries

Note: This endpoint is missing from the routes file. Only individual country operations are available.
To list all countries, you would need to access individual country records or implement a custom index route.

Get Single Country

curl --request GET \
  --url https://api.coreprojects.com/api/paises/1 \
  --header 'Authorization: Bearer YOUR_TOKEN'
{
  "success": true,
  "data": {
    "id_pais": 1,
    "nombre": "Colombia",
    "created_at": "2024-01-15T10:30:00.000000Z",
    "updated_at": "2024-01-15T10:30:00.000000Z",
    "departamentos": [
      {
        "id_departamento": 1,
        "nombre": "Cundinamarca",
        "id_pais": 1,
        "created_at": "2024-01-15T10:35:00.000000Z",
        "updated_at": "2024-01-15T10:35:00.000000Z",
        "ciudades": [
          {
            "id_ciudad": 1,
            "nombre": "Bogotá",
            "codigo_postal": "110111",
            "id_departamento": 1,
            "created_at": "2024-01-15T10:40:00.000000Z",
            "updated_at": "2024-01-15T10:40:00.000000Z"
          }
        ]
      }
    ]
  }
}

Endpoint

GET /api/paises/{id}

Path Parameters

id
integer
required
The unique identifier of the country

Response Fields

success
boolean
Indicates if the request was successful
data
object
The country object with nested departments and cities

Create Country

curl --request POST \
  --url https://api.coreprojects.com/api/paises \
  --header 'Authorization: Bearer YOUR_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "nombre": "Colombia"
  }'
{
  "success": true,
  "message": "País creado exitosamente",
  "data": {
    "id_pais": 1,
    "nombre": "Colombia",
    "created_at": "2024-01-15T10:30:00.000000Z",
    "updated_at": "2024-01-15T10:30:00.000000Z"
  }
}

Endpoint

POST /api/paises

Body Parameters

nombre
string
required
Name of the country (max 80 characters, must be unique)

Validation Rules

  • nombre: Required, string, maximum 80 characters, must be unique in the system

Update Country

curl --request PUT \
  --url https://api.coreprojects.com/api/paises/1 \
  --header 'Authorization: Bearer YOUR_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
    "nombre": "República de Colombia"
  }'
{
  "success": true,
  "message": "País actualizado exitosamente",
  "data": {
    "id_pais": 1,
    "nombre": "República de Colombia",
    "created_at": "2024-01-15T10:30:00.000000Z",
    "updated_at": "2024-01-15T14:20:00.000000Z"
  }
}

Endpoint

PUT /api/paises/{id}

Path Parameters

id
integer
required
The unique identifier of the country to update

Body Parameters

nombre
string
required
Updated name of the country (max 80 characters, must be unique)

Delete Country

curl --request DELETE \
  --url https://api.coreprojects.com/api/paises/1 \
  --header 'Authorization: Bearer YOUR_TOKEN'
{
  "success": true,
  "message": "País eliminado exitosamente"
}

Endpoint

DELETE /api/paises/{id}

Path Parameters

id
integer
required
The unique identifier of the country to delete

Business Rules

A country cannot be deleted if it has associated departments (states). You must first delete all departments before deleting the country.

Relationships

Get States by Country

To retrieve all states/departments for a specific country, use the States API:
GET /api/paises/{id_pais}/departamentos
See the States API documentation for more details.

Build docs developers (and LLMs) love