Introduction
The Inmobiliaria Web API is a RESTful API built with Express.js that provides comprehensive property management, user authentication, and administrative functionality. The API uses JSON for request and response payloads and supports cookie-based authentication via Better Auth.Base URL Configuration
The API base URL is determined dynamically based on the environment:Set the
VITE_API_URL environment variable to override the default API base URL in production environments.API Client
All API requests are made through a centralizedapiCall function that handles:
- Automatic credentials: Includes cookies for session authentication
- Content-Type negotiation: Automatically sets headers based on request body type
- Error handling: Parses and throws descriptive errors
- Response validation: Ensures JSON responses are returned
Request Format
Response Format
All API responses follow a consistent structure:Error Handling
The API client implements comprehensive error handling:Common Error Codes
| Status Code | Description | Common Causes |
|---|---|---|
| 400 | Bad Request | Invalid request data, missing required fields |
| 401 | Unauthorized | Missing or invalid session cookie |
| 403 | Forbidden | Insufficient permissions for the requested resource |
| 404 | Not Found | Resource does not exist |
| 500 | Internal Server Error | Server-side error, check server logs |
API Namespaces
The API is organized into the following namespaces:Properties
Manage property listings, including creation, updates, and filtering.GET /properties- List properties with optional filtersGET /properties/:id- Get property by IDGET /properties/slug/:slug- Get property by URL slugPOST /properties- Create new property (requires authentication)PUT /properties/:id- Update property (requires authentication)DELETE /properties/:id- Delete property (requires authentication)POST /properties/:id/favorite- Add property to favoritesDELETE /properties/:id/favorite- Remove property from favorites
Property creation and updates accept
FormData to support image uploads. The API client automatically handles Content-Type headers for multipart requests.Users
Manage user profiles and favorites.GET /users/profile- Get current user profile (requires authentication)PUT /users/profile- Update user profile (requires authentication)GET /users/favorites- Get user’s favorite properties (requires authentication)
Admin
Administrative operations for managing users and properties.GET /admin/stats- Get dashboard statistics (requires admin role)GET /admin/properties- List all properties (requires admin role)GET /admin/users- List all users (requires admin role)PUT /admin/users/:id/role- Update user role (requires admin role)PUT /admin/properties/:id/status- Update property status (requires admin role)POST /admin/create-admin- Create new admin user (requires admin role)
Metadata
Retrieve system metadata for property types, features, tags, and more.GET /metadata/all- Get all metadata in one requestGET /metadata/property-types- Get available property typesGET /metadata/property-subtypes- Get property subtypes (optionally filtered by type)GET /metadata/operation-types- Get operation types (sale, rent, etc.)GET /metadata/property-statuses- Get available property statusesGET /metadata/currencies- Get supported currenciesGET /metadata/features- Get available property featuresGET /metadata/tags- Get available tagsGET /metadata/conditions- Get property condition options
Contact
Handle contact form submissions and appraisal requests.POST /contact/appraisal- Submit property appraisal or contact request
Usage Example
Here’s how to use the API client in your application:Next Steps
Authentication
Learn how to authenticate users with Better Auth
Properties
Explore property management endpoints
Users
Manage user profiles and preferences
Admin
Administrative operations and dashboard