Fix undefined variable in api.php