Enable and Disable Permanent Users
- permanent_user_disable_enable.php
<?php
// Configuration
$server = 'http://127.0.0.1';
$api_url = "$server/cake4/rd_cake/permanent-users/enable-disable.json";
$token = 'b4c6ac81-8c7c-4802-b50a-0a6380555b50';
$cloud_id = 23; // replace with the Cloud ID that you want to work on.
$username = 'testuser@dev';
$action = 'disable'; //Options 'enable' or 'disable'
// Filter settings
$filter = 'username'; //field that filter should apply to
$operator = '=='; //Options '==','like'
$value = $username; //can also be set to boolean e.g. true or false to filter for instance on the 'active' field
$limit = 1000;
$filter_array = [
[
"operator" => $operator,
"value" => $value, // this stays a boolean!
"property" => $filter
]
];
$encoded_filter = urlencode(json_encode($filter_array));
$find_url = "$server/cake4/rd_cake/permanent-users/index.json?page=1&start=0&limit=$limit&filter=$encoded_filter&token=$token&cloud_id=$cloud_id";
$listOfIds = getIds();
if($listOfIds){
$listOfIds['cloud_id'] = $cloud_id;
$listOfIds['token'] = $token;
$listOfIds['rb'] = $action;
$json_payload = json_encode($listOfIds);
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
curl_close($ch);
echo "Response: $response\n";
}
function getIds(){
global $find_url;
// Create stream context with headers
$context = stream_context_create([
'http' => [
'header' => "Accept: application/json\r\n" .
"Content-Type: application/json\r\n"
]
]);
print($find_url);
// Get the response
$response = file_get_contents($find_url, false, $context);
if ($response === false) {
echo "Error fetching data";
exit;
}
// Decode JSON
$data = json_decode($response, true);
if (!empty($data['items']) && is_array($data['items'])) {
$count = count($data['items']);
$listOfIds = [];
foreach($data['items'] as $permanentUser){
$id = $permanentUser['id'];
$listOfIds[$id] = $id;
}
echo "There $count items\n";
return $listOfIds;
} else {
echo "No items.";
}
return false;
}
?>
$username = '@dev';
$action = 'disable'; //Options 'enable' or 'disable'
// Filter settings
$filter = 'username'; //field that filter should apply to
$operator = 'like'; //Options '==','like'
$value = $username; //can also be set to boolean e.g. true or false to filter for instance on the 'active' field
$limit = 1000;
$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;