Creating Properties
Learn how to create new property listings in the Sistema de Gestión de Propiedades API using thePOST /api/propiedades endpoint.
Endpoint
Required Fields
When creating a property, you must provide:pais(string) - Countryciudad(string) - Citydireccion(string) - Street addressambientes(number) - Number of roomsmetros_cuadrados(number) - Square metersprecio(number) - Pricetipo_contratacion(enum) - “Alquiler” or “Venta”estado(enum) - “Disponible”, “Reservado”, “Alquilado”, or “Vendido”
Optional Fields
codigo_id(string, 6 characters) - Custom property ID. If not provided, one will be auto-generateddescripcion(string) - Property description
Property ID Generation
The API handles property IDs intelligently:- Auto-generated
- Custom ID
If you don’t provide a The API will:
codigo_id, the API automatically generates a unique 6-character alphanumeric ID:- Generate a random 6-character ID (e.g., “A7K92M”)
- Check for uniqueness in the database
- Retry up to 5 times if there’s a collision
- Return the generated ID in the response
ID generation uses alphanumeric characters excluding
O (letter O) to avoid confusion with 0 (zero).Character set: ABCDEFGHIJKLMNPQRSTUVWXYZ123456789Source: Backend/src/controllers/propiedades.controller.ts:24-30Basic Example
Success Response
Status Code:201 Created
id field contains the property’s codigo_id (either the one you provided or the auto-generated one).
Complete Examples
Rental Property (Auto-generated ID)
Sale Property (Custom ID)
Minimal Property (Required Fields Only)
Error Responses
400 Bad Request - Validation Error
Returned when the request data doesn’t match the schema:codigo_id must be exactly 6 characters
codigo_id must be exactly 6 characters
Invalid tipo_contratacion
Invalid tipo_contratacion
Must be exactly “Alquiler” or “Venta” (case-sensitive):
Invalid estado
Invalid estado
Must be one of: “Disponible”, “Reservado”, “Alquilado”, “Vendido”
Missing required fields
Missing required fields
- pais, ciudad, direccion
- ambientes, metros_cuadrados, precio
- tipo_contratacion, estado
Invalid data types
Invalid data types
401 Unauthorized
Returned when authentication is missing or invalid:409 Conflict - Duplicate ID
Returned when you provide acodigo_id that already exists:
- Use a different
codigo_id - Omit
codigo_idto let the API auto-generate one
Field Validation Rules
| Field | Type | Constraints |
|---|---|---|
| codigo_id | string | Exactly 6 characters (optional) |
| pais | string | Required |
| ciudad | string | Required |
| direccion | string | Required |
| ambientes | number | Required, integer |
| metros_cuadrados | number | Required, can be decimal |
| precio | number | Required, can be decimal |
| tipo_contratacion | enum | ”Alquiler” or “Venta” |
| estado | enum | ”Disponible”, “Reservado”, “Alquilado”, “Vendido” |
| descripcion | string | Optional |
Best Practices
Validate locally first
Check your data matches the schema before sending the request to avoid unnecessary API calls.
Let the API generate IDs
Unless you have a specific naming convention, let the API auto-generate unique IDs.
Use descriptive descriptions
The
descripcion field helps users understand property features at a glance.Set appropriate status
New properties should typically have
estado: "Disponible" unless they’re pre-reserved.Implementation Details
The creation logic (fromBackend/src/controllers/propiedades.controller.ts:32-96):
- Parse the request body
- Determine ID (provided or generate)
- Check for uniqueness (retry up to 5 times for auto-generated IDs)
- Validate against Zod schema
- Insert into database
- Return success with the property ID
Next Steps
Update Properties
Learn how to update existing properties
Query Properties
Retrieve and filter property listings
Error Handling
Handle API errors gracefully
API Reference
Complete API reference for this endpoint