diff --git a/lib/API.php b/lib/API.php
index 3220e21dcb83c7af740488f483a7b3cc69fbe8fb..3966dfc96552e62b7cb40d6e4c0e83fa9141750b 100644
--- a/lib/API.php
+++ b/lib/API.php
@@ -297,7 +297,7 @@ class API {
                 }
                 break;
             case 'only_errors':
-                if ($optValue != 1) {
+                if ($optValue != 1 && $optValue != 2) {
                     $optValue = 0;
                 }
             case 'details':
@@ -577,8 +577,8 @@ class API {
                     'arg' => 'only_errors',
                     'required' => FALSE,
                     'default' => '0',
-                    'values' => '0, 1',
-                    'description' => '0 - show all; 1 - only federations with feed problems including close to expiry'],
+                    'values' => '0, 1, 2',
+                    'description' => '0 - show all; 1 - only federations with feed problems including close to expiry; 2 - show only federations with expiry time below the set valid_sec value'],
                 [
                     'arg' => 'valid_sec',
                     'required' => FALSE,
@@ -611,7 +611,7 @@ class API {
         Utils::debug(5, $this->opts, "OPTS: ", "\n");
         $edugain = new eduGAIN(5, $this->fed_id, true);
         $edugain->load_federations_state();
-        if ($this->opts['only_errors'] == 1) {
+        if ($this->opts['only_errors'] > 0) {
             $out = [];
             if ($this->opts['valid_sec'] > 0) {
                 $sec = $this->opts['valid_sec'];
@@ -619,8 +619,15 @@ class API {
                 $sec = VALIDITY_WARNING_THRESHOLD;
             }
             foreach ($edugain->FEDS as $fed) {
-                if ($fed['feed_problem'] > 0 || $fed['valid_sec'] < $sec) {
-                    $out[$fed['code']] = $fed;
+                if ($this->opts['only_errors'] == 2) {
+                    if ($fed['valid_sec'] < $sec) {
+                        $out[$fed['code']] = $fed;
+                    }
+                }
+                if ($this->opts['only_errors'] == 1) {
+                    if ($fed['valid_sec'] < $sec || $fed['feed_problem'] > 0 ) {
+                        $out[$fed['code']] = $fed;
+                    }
                 }
             }