Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
technical:api-pu-delete [2025/04/13 14:43] systemtechnical:api-pu-delete [2025/04/13 15:01] (current) – [Delete Permanent Users] system
Line 1: Line 1:
 <nav type="pills" justified="false"> <nav type="pills" justified="false">
   * [[:user_manuals|Back to Documentation]]   * [[:user_manuals|Back to Documentation]]
-  * [[:technical:api-pu-delete|Delete Permanent USer]]+  * [[:technical:api-pu-delete|Delete Permanent Users]]
 </nav> </nav>
  
 ----- -----
  
-====== Delete Permanent User ======+====== Delete Permanent Users ======
  
-  * To terminate user's active sessions we will work on a filtered list of active sessions for a user.+  * To delete Permanent User we have to first determine the id of the Permanent User. 
 +  * A CRM system typically do not know the id of the Permanent User in RADIUSdesk.
   * With the sample script we use two APIs   * With the sample script we use two APIs
-      * The one API is used get a list of active sessions for a specified Permanent User, if there are any+      * The one API is used get a list of Permanent Users to collect their ids
-      * The other API is used to terminate each of the sessions which was obtained with the first API call.+      * The other API is used to delete the list of Permanent Users which was obtained.
 <file php permanent_user_delete.php> <file php permanent_user_delete.php>
 <?php <?php
Line 21: Line 22:
  
 $username   = 'testuser@dev'; $username   = 'testuser@dev';
-$api_url    = "$server/cake4/rd_cake/radaccts/kick-active.json"; 
  
 +$api_url    = "$server/cake4/rd_cake/permanent-users/delete.json";
 +
 + 
 // Filter settings // Filter settings
 $filter     = 'username'; //field that filter should apply to $filter     = 'username'; //field that filter should apply to
Line 36: Line 39:
 ]]; ]];
 $encoded_filter = urlencode(json_encode($filter_array)); $encoded_filter = urlencode(json_encode($filter_array));
-$find_url = "$server/cake4/rd_cake/radaccts/index.json?page=1&start=0&limit=1000&filter=$encoded_filter&token=$token&cloud_id=$cloud_id&only_connected=true";+$find_url = "$server/cake4/rd_cake/permanent-users/index.json?page=1&start=0&limit=1000&filter=$encoded_filter&token=$token&cloud_id=$cloud_id";
  
 // Get User IDs // Get User IDs
Line 46: Line 49:
             'cloud_id'  => $cloud_id,             'cloud_id'  => $cloud_id,
             'token'     => $token,             'token'     => $token,
-            $id         => $id+            'id       => $id
         ];         ];
-        print_r($payload); + 
-        $response = sendDisconnectRequest($api_url, $payload); +        $response = sendPostRequest($api_url, $payload); 
-        echo "Terminated Session ID $id - Response: $response\n";+        echo "Updated ID $id - Response: $response\n";
     }     }
 } }
Line 80: Line 83:
 } }
  
-function sendDisconnectRequest($url, $data) { +function sendPostRequest($url, $data) { 
- +    $ch = curl_init($url);
-    // Build the query string from $data +
-    $queryString = http_build_query($data); +
- +
-    // Append it to the URL +
-    $urlWithParams = $url . '?' . $queryString; +
- +
-    $ch = curl_init($urlWithParams);+
     curl_setopt_array($ch, [     curl_setopt_array($ch, [
         CURLOPT_RETURNTRANSFER => true,         CURLOPT_RETURNTRANSFER => true,
-        CURLOPT_HTTPHEADER     => ['Accept: application/json'// optional+        CURLOPT_POST           => true, 
 +        CURLOPT_POSTFIELDS     => json_encode($data), 
 +        CURLOPT_HTTPHEADER     => ['Content-Type: application/json']
     ]);     ]);
- 
     $response = curl_exec($ch);     $response = curl_exec($ch);
     if ($response === false) {     if ($response === false) {
Line 103: Line 100:
 ?> ?>
 </file> </file>
-  * We are not limited to only one user but we can adjust the filter for instance to terminate the sessions of all the users with a specific suffix e.g. @dev.+  * We are not limited to only one user but we can for instance delete all the users with a specific suffix e.g. @dev.
   * For this we have to make the following adjustments:   * For this we have to make the following adjustments:
 <code php> <code php>
Line 115: Line 112:
 </code> </code>
  
 +  * By the same token, if we want to delete all disabled users we can adjust the filter as follows:
 +
 +<code php>
 +$action     = 'enable'; //Options 'enable' or 'disable'
 + 
 +// Filter settings
 +$filter     = 'active'; //field that filter should apply to
 +$operator   = '==';  //Options '==','like' 
 +$value      = false; //can also be set to boolean e.g. true or false to filter for instance on the 'active' field
 +$limit      = 1000;
 +</code>
  • technical/api-pu-delete.1744548213.txt.gz
  • Last modified: 2025/04/13 14:43
  • by system