diff --git a/html/api_v0.php b/html/api_v0.php index 2e965a410d..550506db18 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -45,6 +45,10 @@ $app->group('/api', function() use ($app) { $app->group('/portgroups', function() use ($app) { $app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup');//api/v0/portgroups/$group }); + $app->group('/bills', function() use ($app) { + $app->get('/:bill_id', 'authToken', 'list_bills')->name('get_bill');//api/v0/bills/$bill_id + }); + $app->get('/bills', 'authToken', 'list_bills')->name('list_bills');//api/v0/bills }); $app->get('/v0', 'authToken', 'show_endpoints');//api/v0 }); diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index c8b40bb2af..a02ef291b0 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -465,3 +465,33 @@ function get_port_graphs() { $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); } + +function list_bills() { + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $bill_id = $router['bill_id']; + if(isset($_GET['custid'])) { + $sql = "`bill_custid` = ?"; + $param = array($_GET['custid']); + } elseif(isset($_GET['ref'])) { + $sql = "`bill_ref` = ?"; + $param = array($_GET['ref']); + } elseif(is_numeric($bill_id)) { + $sql = "`bill_id` = ?"; + $param = array($bill_id); + } else { + $sql = ""; + $param = array(); + } + if(count($param) >= 1) { + $sql = "WHERE $sql"; + } + $bills = dbFetchRows("SELECT * FROM `bills` $sql",$param); + $total_bills = count($bills); + $output = array("status" => "ok", "err-msg" => '', "count" => $total_bills, "bills" => $bills); + $app->response->setStatus('200'); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); +} + diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index 02d9330b8e..83ebc78fc7 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -319,11 +319,52 @@ if ($_SESSION['userlevel'] == '10')
curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/devices/localhost/ports?columns=ifDescr,ifName"
curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/bills"
curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/bills?custid=Testing"
curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/bills/$bill_id"