diff --git a/doc/API/API-Docs.md b/doc/API/API-Docs.md index fb376dd684..2313cc0395 100644 --- a/doc/API/API-Docs.md +++ b/doc/API/API-Docs.md @@ -1158,7 +1158,7 @@ Route: /api/v0/devicegroups/:name Input (JSON): - - + -full: set to true to return all columns for the devices in a group Examples: ```curl diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index b66830e662..c5b357c799 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -1381,13 +1381,14 @@ function get_devices_by_group() $status = 'error'; $code = 404; $count = 0; - $name = urldecode($router['name']); - $devices = array(); + $name = urldecode($router['name']); + $devices = array(); + $full = $_GET['full']; if (empty($name)) { $message = 'No device group name provided'; } else { $group_id = dbFetchCell("SELECT `id` FROM `device_groups` WHERE `name`=?", array($name)); - $devices = GetDevicesFromGroup($group_id, true); + $devices = GetDevicesFromGroup($group_id, true, $full); $count = count($devices); if (empty($devices)) { $message = 'No devices found in group ' . $name; @@ -1404,6 +1405,7 @@ function get_devices_by_group() 'devices' => $devices, ); + logfile(var_dump($output)); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); diff --git a/includes/device-groups.inc.php b/includes/device-groups.inc.php index f47a691e2a..3b314659bb 100644 --- a/includes/device-groups.inc.php +++ b/includes/device-groups.inc.php @@ -188,11 +188,16 @@ function QueryDevicesFromGroup($group_id) * Get an array of all the device ids belonging to this group_id * @param $group_id * @param bool $nested Return an array of arrays containing 'device_id'. (for API compatibility) + * @param bool $full Return all fields from devices_id * @return array */ -function GetDevicesFromGroup($group_id, $nested = false) +function GetDevicesFromGroup($group_id, $nested = false, $full = false) { - $query = 'SELECT `device_id` FROM `device_group_device` WHERE `device_group_id`=?'; + if ($full) { + $query = 'SELECT `device_groups`.`name`, `devices`.* FROM `device_groups` INNER JOIN `device_group_device` ON `device_groups`.`id` = `device_group_device`.`device_group_id` INNER JOIN `devices` ON `device_group_device`.`device_id` = `devices`.`device_id` WHERE `device_groups`.`id`=?'; + } else { + $query = 'SELECT `device_id` FROM `device_group_device` WHERE `device_group_id`=?'; + } if ($nested) { return dbFetchRows($query, array($group_id)); } else { diff --git a/includes/functions.php b/includes/functions.php index 30d0437e6d..4cfd596e83 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1119,6 +1119,9 @@ if (!defined('JSON_UNESCAPED_UNICODE')) { function _json_encode($data, $options = 448) { + array_walk_recursive($data, function (&$val) { + $val = utf8_encode($val); + }); if (version_compare(PHP_VERSION, '5.4', '>=')) { return json_encode($data, $options); } else {