Skip to main content

Updating Properties

Update existing property information using the PATCH /api/propiedades/{id} endpoint. This endpoint supports partial updates - you only need to send the fields you want to change.
This endpoint requires authentication. See the Authentication guide for setup instructions.

Endpoint

PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/{id}

Key Concepts

Partial Updates

You only need to send the fields you want to update. All fields are optional in a PATCH request:
# Update only the price
curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{"precio": 125000}'

Immutable ID

The codigo_id cannot be changed after creation. Any attempt to modify it will result in a 400 Bad Request error.
# This will fail
curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{"codigo_id": "NEW123"}'

# Error response
{
  "success": false,
  "error": "No está permitido modificar el código identificador de la propiedad."
}
Source: Backend/src/controllers/propiedades.controller.ts:105-110

Basic Example

curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{
    "precio": 125000,
    "estado": "Reservado"
  }'

Success Response

Status Code: 200 OK
{
  "success": true,
  "message": "Propiedad actualizada"
}

Common Update Scenarios

Update Property Status

Mark a property as reserved, rented, or sold:
# Mark as reserved
curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{"estado": "Reservado"}'

# Mark as rented
curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{"estado": "Alquilado"}'

# Mark as sold
curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{"estado": "Vendido"}'

Update Price

curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{"precio": 135000}'

Update Description

curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{
    "descripcion": "Hermosa vista al río. Recientemente renovada con cocina nueva."
  }'

Update Multiple Fields

curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{
    "precio": 140000,
    "descripcion": "Precio actualizado. Excelente oportunidad.",
    "estado": "Disponible"
  }'

Change Contract Type

# Change from rental to sale
curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{
    "tipo_contratacion": "Venta",
    "precio": 2500000,
    "estado": "Disponible"
  }'

Updatable Fields

All fields except codigo_id can be updated:
FieldTypeExample
paisstring”Argentina”
ciudadstring”Buenos Aires”
direccionstring”Av. Corrientes 1234”
ambientesnumber3
metros_cuadradosnumber85.5
precionumber125000
tipo_contratacionenum”Alquiler” or “Venta”
estadoenum”Disponible”, “Reservado”, “Alquilado”, “Vendido”
descripcionstring”Casa con vista al río”
codigo_id is immutable and cannot be updated.

Error Responses

400 Bad Request - Attempting to Change ID

{
  "success": false,
  "error": "No está permitido modificar el código identificador de la propiedad."
}

400 Bad Request - Validation Error

{
  "success": false,
  "error": "Invalid input: estado must be one of Disponible, Reservado, Alquilado, Vendido"
}

401 Unauthorized

{
  "error": "Unauthorized"
}

404 Not Found

Returned when the property ID doesn’t exist:
{
  "success": false,
  "error": "Propiedad no encontrada"
}

Implementation Details

The update logic uses COALESCE to only update provided fields (from Backend/src/controllers/propiedades.controller.ts:99-153):
export const updatePropiedad = async (c: Context) => {
  const id = c.req.param('id');
  const body = await c.req.json();
  
  // Prevent ID modification
  if (body.codigo_id && body.codigo_id !== id) {
    return c.json({ 
      success: false, 
      error: "No está permitido modificar el código identificador de la propiedad." 
    }, 400);
  }
  
  // Validate with partial schema (all fields optional)
  const validated = PropiedadSchema.partial().parse(body);
  
  // Update only provided fields using COALESCE
  const result = await c.env.DB.prepare(`
    UPDATE propiedades SET 
      pais = COALESCE(?, pais),
      ciudad = COALESCE(?, ciudad),
      precio = COALESCE(?, precio),
      estado = COALESCE(?, estado),
      // ... other fields
    WHERE codigo_id = ?
  `).bind(...values, id).run();
  
  if (result.meta.changes === 0) {
    return c.json({ success: false, error: "Propiedad no encontrada" }, 404);
  }
  
  return c.json({ success: true, message: 'Propiedad actualizada' });
};

Validation Rules

The same validation rules apply as when creating properties:
  • estado must be: “Disponible”, “Reservado”, “Alquilado”, or “Vendido”
  • tipo_contratacion must be: “Alquiler” or “Venta”
  • Numbers must be sent as numbers, not strings
  • All enum values are case-sensitive
See Validation Rules for complete details.

Best Practices

1

Send only changed fields

Only include fields you’re actually updating to minimize payload size and clarify intent.
2

Verify property exists first

Use GET /api/propiedades/{id} to confirm the property exists before updating.
3

Update status atomically

When marking a property as sold/rented, consider updating the price or description at the same time.
4

Handle 404 errors

If you get a 404, the property may have been deleted. Don’t retry the request.
5

Validate locally

Check enum values and data types before sending to avoid validation errors.

Workflow Example

Complete workflow for updating a property:
1

Fetch current property

curl https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001
2

Determine changes

Review current values and decide what needs updating.
3

Send PATCH request

curl -X PATCH https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001 \
  -u admin:password \
  -H "Content-Type: application/json" \
  -d '{"precio": 125000, "estado": "Reservado"}'
4

Verify update

curl https://idforideas-1.jamrdev.com.ar/api/propiedades/ZN1001
Confirm the fields were updated correctly.

Next Steps

Query Properties

Learn how to retrieve property information

Creating Properties

Guide on creating new properties

Error Handling

Handle API errors gracefully

API Reference

Complete API reference for this endpoint

Build docs developers (and LLMs) love