function apiAbort(obj) { writeOutput(serializeJSON(obj)); abort; } function readJsonBody() { raw = toString(getHttpRequestData().content); if (isNull(raw) || len(trim(raw)) EQ 0) return {}; try { parsed = deserializeJSON(raw); } catch(any e) { apiAbort({ OK=false, ERROR="bad_json", MESSAGE="Invalid JSON body" }); } if (!isStruct(parsed)) return {}; return parsed; } data = readJsonBody(); if (!structKeyExists(data, "BeaconID") || !isNumeric(data.BeaconID) || int(data.BeaconID) LTE 0) { apiAbort({ OK=false, ERROR="missing_beacon_id", MESSAGE="BeaconID is required" }); } beaconId = int(data.BeaconID); SELECT BeaconID, BeaconName, BeaconUUID, BeaconBusinessID FROM Beacons WHERE BeaconID = AND BeaconIsActive = 1 LIMIT 1 #serializeJSON({ OK=false, ERROR="not_found", MESSAGE="Beacon not found or inactive" })# SELECT lt.BusinessID, lt.ServicePointID, biz.BusinessName, biz.BusinessParentBusinessID, sp.ServicePointName FROM lt_Beacon_Businesses_ServicePoints lt INNER JOIN Businesses biz ON biz.BusinessID = lt.BusinessID INNER JOIN ServicePoints sp ON sp.ServicePointID = lt.ServicePointID WHERE lt.BeaconID = AND sp.ServicePointIsActive = 1 ORDER BY biz.BusinessParentBusinessID IS NULL DESC, biz.BusinessName ASC #serializeJSON(response)#