updated api.php for new db structure