Overview
ThecreateParkingSpot endpoint creates a new parking spot or updates an existing one using merge semantics. It’s typically used during system setup or when adding new spots to the parking system.
Endpoint
Authentication
CORS-enabled endpoint with wildcard origin (*). Should be restricted to admin users in production.
Request Body
Unique identifier for the parking spot (e.g., “A-01”, “I-16”). Will be trimmed and converted to uppercase.
Latitude coordinate of the parking spot location (e.g., -33.4489)
Longitude coordinate of the parking spot location (e.g., -70.6693)
Human-readable description of the spot. Defaults to “Puesto ” if not provided.
ID of the zone this spot belongs to (e.g., “zone_1764307623391”). Defaults to
null if not provided.Initial status of the parking spot:
0: Occupied1: Available (default)2: Reserved
Response
Indicates whether the operation was successful
Result message: “Puesto creado/actualizado”
The created/updated spot object with all fields
Error message (only present on failure)
Success Response
- 200 OK - Spot created or updated successfully
- 204 No Content - OPTIONS preflight response
Error Responses
-
400 Bad Request - Missing or invalid parameters:
- Missing
idfield - Invalid coordinates (lat/lng are not numbers)
- Missing
- 500 Internal Server Error - Database or server error
Merge Semantics
The function uses Firestore’smerge: true option:
- If spot exists: Updates only the provided fields, preserves existing fields
- If spot doesn’t exist: Creates new document with all provided fields
Code Example
Success Response Example
Error Response Examples
Missing ID
Invalid Coordinates
Firestore Data Structure
The created/updated document inparking_spots collection:
Data Processing
- ID normalization: Trimmed and converted to uppercase (“a-01” → “A-01”)
- Coordinate validation: Parsed as floats and validated as numbers
- Default values:
status:1(Available) if not provideddesc: “Puesto ” if not providedzone_id:nullif not provided
- Timestamps: Automatically set
created_atandupdated_at
Bulk Creation Pattern
For creating multiple spots, call this endpoint in parallel:Related Endpoints
- Delete Parking Spot - Remove a parking spot
- Manage Zones - Create zones before assigning spots
- Get Parking Status - Verify spot was created successfully