Files
whatsapp/api/get_notifications.php
T
2026-01-28 13:49:07 -05:00

23 lines
729 B
PHP

<?php
require_once '../config/config.php';
requireAuthentication();
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
try {
$db = Database::getInstance();
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 20;
$rows = $db->fetchAll(
"SELECT id, user_id, type, message, data, is_read, created_at FROM notifications WHERE is_read = 0 ORDER BY created_at DESC LIMIT ?",
[$limit]
);
echo json_encode(['success' => true, 'data' => $rows]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}