Skip to main content

Overview

The getParkingStatus endpoint returns the current status of all parking spots in the system. It automatically expires and clears reservations that have passed their expiration time before returning the data.

Endpoint

GET /get-parking-status

Authentication

CORS-enabled endpoint accessible from web applications. Configure allowed origins in production.

Request

No parameters required. This is a simple GET request.

Response

spots
array
Array of parking spot objects
spots[].id
string
Unique spot identifier (e.g., “A-01”, “I-16”)
spots[].status
integer
Current spot status:
  • 0: Occupied
  • 1: Available
  • 2: Reserved
spots[].lat
number
Latitude coordinate of the parking spot
spots[].lng
number
Longitude coordinate of the parking spot
spots[].desc
string
Description of the parking spot
spots[].zone_id
string
ID of the zone this spot belongs to (e.g., “zone_1764307623391”)
spots[].last_changed
timestamp
Firestore timestamp of the last status change
spots[].reservation_data
object
Present only when status is 2 (Reserved). Contains:
  • license_plate: Vehicle license plate
  • expires_at: Firestore timestamp of expiration
  • duration: Reservation duration in minutes

Success Response

  • 200 OK - Returns array of parking spots with current status

Error Response

  • 500 Internal Server Error - Database or server error

Automatic Expiration Logic

The function checks all reserved spots (status === 2) for expiration:
  1. Expiration Check: Compares current time with reservation_data.expires_at
  2. Batch Update: If expired, updates spot to status 1 (Available) and deletes reservation data
  3. Immediate Response: Returns corrected status without waiting for next request
  4. Background Commit: Database updates are committed asynchronously using Firestore batch operations

Code Example

curl -X GET https://YOUR_REGION-YOUR_PROJECT.cloudfunctions.net/get-parking-status

Response Example

[
  {
    "id": "A-01",
    "status": 0,
    "lat": -33.4489,
    "lng": -70.6693,
    "desc": "Puesto A-01",
    "zone_id": "zone_1764307623391",
    "last_changed": {
      "_seconds": 1704900000,
      "_nanoseconds": 0
    }
  },
  {
    "id": "A-02",
    "status": 2,
    "lat": -33.4490,
    "lng": -70.6694,
    "desc": "Puesto A-02",
    "zone_id": "zone_1764307623391",
    "last_changed": {
      "_seconds": 1704900120,
      "_nanoseconds": 0
    },
    "reservation_data": {
      "license_plate": "ABC123",
      "expires_at": {
        "_seconds": 1704903720,
        "_nanoseconds": 0
      },
      "duration": 60
    }
  },
  {
    "id": "I-01",
    "status": 1,
    "lat": -33.4495,
    "lng": -70.6700,
    "desc": "Puesto I-01",
    "zone_id": "zone_1764306251630",
    "last_changed": {
      "_seconds": 1704899500,
      "_nanoseconds": 0
    }
  }
]

Performance Considerations

  • Batch Operations: Expired reservations are updated in a single batch commit for efficiency
  • Real-time Cleanup: Expiration checks happen on every request, ensuring fresh data
  • No Polling Required: Clients receive automatically corrected data

Build docs developers (and LLMs) love