From 36a2b1a6e7a31650a713071e880945c0b7290b55 Mon Sep 17 00:00:00 2001 From: jasonMPM Date: Wed, 4 Mar 2026 22:22:04 -0600 Subject: [PATCH] Update app.py --- app.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 05c7a0c..5568412 100644 --- a/app.py +++ b/app.py @@ -158,7 +158,11 @@ def receive_webhook(): # Data block per UniFi Access docs: payload["data"]["actor"], ["event"], etc. data = payload.get("data") or {} actor_obj = data.get("actor") or {} - actor = actor_obj.get("id") or payload.get("actor_id", "") + actor = ( + actor_obj.get("id") + or actor_obj.get("identity_id") + or payload.get("actor_id", "") + ) if "access.door.unlock" not in str(event): # Ignore other notification types @@ -256,6 +260,36 @@ def reset_day(): return jsonify({"status": "ok", "deleted": cur.rowcount, "date": date}) +@app.route("/api/debug-user-cache") +def debug_user_cache(): + """Temporary helper to see what the Access API returns for a webhook actor.""" + actor_id = request.args.get("actor_id", "").strip() + if not actor_id: + return jsonify({"error": "missing actor_id"}), 400 + + try: + r = requests.get( + f"{UNIFI_BASE}/users/search", + headers={"Authorization": f"Bearer {UNIFI_TOKEN}"}, + params={"userid": actor_id}, + verify=False, + timeout=10, + ) + try: + data = r.json() + except Exception: + data = {"raw": r.text[:500]} + return jsonify( + { + "status_code": r.status_code, + "actor_id_param": actor_id, + "response": data, + } + ) + except Exception as e: + return jsonify({"error": str(e)}), 500 + + # Initialise DB and kick off background scheduler at import time with app.app_context(): init_db() -- 2.49.1