Skip to main content

Update Location

Submit location coordinates to record attendance. This endpoint creates a new attendance record with the current timestamp and user’s location.
POST /update-location
This endpoint requires authentication. You must be logged in to submit location data.

Request Parameters

lat
number
required
The latitude coordinate of the user’s current location.Example: 19.432608
lon
number
required
The longitude coordinate of the user’s current location.Example: -99.133209

Request Format

The endpoint expects JSON-encoded data (Content-Type: application/json).

Response

status
string
Always returns “OK” on successful submission.

Success Response

{
  "status": "OK"
}

Code Examples

curl -X POST http://localhost:5000/update-location \
  -H "Content-Type: application/json" \
  -b cookies.txt \
  -d '{
    "lat": 19.432608,
    "lon": -99.133209
  }'

Implementation Details

The endpoint implementation (app.py:116-132):
@app.route('/update-location', methods=['POST'])
@login_required
def update_location():
    data = request.json
    registros = leer_json(REGISTROS_FILE)
    ahora = datetime.datetime.now()
    
    nuevo = {
        "usuario": current_user.id,
        "lat": data['lat'],
        "lon": data['lon'],
        "fecha": ahora.strftime("%Y-%m-%d"),
        "hora": ahora.strftime("%H:%M:%S")
    }
    registros.append(nuevo)
    guardar_json(REGISTROS_FILE, registros)
    return jsonify({"status": "OK"})

Behavior

When you submit location data:
  1. The system automatically captures the current timestamp
  2. The date is stored in YYYY-MM-DD format
  3. The time is stored in HH:MM:SS format (24-hour)
  4. The record is associated with the authenticated user (current_user.id)
  5. The data is appended to data/registros.json

Attendance Status

Records submitted after 08:30:00 are marked as “RETARDO” (late) in the monitoring dashboard. Records submitted at or before 08:30:00 are marked as “PUNTUAL” (on time).

Data Persistence

All location records are stored in data/registros.json with the following structure:
[
  {
    "usuario": "empleado1",
    "lat": 19.432608,
    "lon": -99.133209,
    "fecha": "2026-03-05",
    "hora": "08:15:30"
  }
]
See the Attendance Record Model for complete field descriptions.

Build docs developers (and LLMs) love