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 ID, Name, UUID, BusinessID FROM Beacons WHERE ID = AND IsActive = 1 LIMIT 1 #serializeJSON({ OK=false, ERROR="not_found", MESSAGE="Beacon not found or inactive" })# SELECT sp.ServicePointBusinessID AS BusinessID, sp.ServicePointID AS ServicePointID, biz.BusinessName AS BusinessName, biz.BusinessParentBusinessID, sp.ServicePointName AS ServicePointName FROM ServicePoints sp INNER JOIN Businesses biz ON biz.BusinessID = sp.ServicePointBusinessID WHERE sp.BeaconID = AND sp.IsActive = 1 UNION SELECT lt.BusinessID, 0 AS ServicePointID, biz.BusinessName AS BusinessName, biz.BusinessParentBusinessID, '' AS ServicePointName FROM lt_BeaconsID_BusinessesID lt INNER JOIN Businesses biz ON biz.BusinessID = lt.BusinessID WHERE lt.BeaconID = AND lt.BusinessID NOT IN ( SELECT sp2.ServicePointBusinessID FROM ServicePoints sp2 WHERE sp2.BeaconID = AND sp2.IsActive = 1 ) ORDER BY BusinessParentBusinessID IS NULL DESC, BusinessName ASC SELECT COUNT(*) as cnt FROM Businesses WHERE BusinessParentBusinessID = SELECT BusinessName, BusinessHeaderImageExtension FROM Businesses WHERE BusinessID = SELECT BusinessID, BusinessName, BusinessParentBusinessID, BusinessHeaderImageExtension FROM Businesses WHERE BusinessParentBusinessID = ORDER BY BusinessName ASC try{logPerf(0);}catch(any e){} #serializeJSON(response)#