Error when deactivating a user via the API

When I want to set the value ‘disabled’ to the current date via API, I get the following error message: “body”:{“disabled”:{“dateTime”: “The disabled date should be a valid date.”}.

I use PHP to generate the date:
$currentDateTime = date(‘Y-m-d\TH:i:sP’);

My PHP code:
$currentDateTime = date(‘Y-m-d\TH:i:sP’);
$data = [
‘active’ => false,
‘disabled’ => $currentDateTime,
‘changed’ => $currentDateTime
];
// Step 2: PUT call with the CSRF token cookie
$ch = curl_init($config[‘server_url’] . ‘/users/.json?api-version=v2’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “PUT”);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $gpgAuth->getCookie());
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-CSRF-Token: ’ . $csrfToken,
‘Accept: application/json’,
‘Content-Type: application/json’,
'Cookie: ’ . $sessionCookie
));
$response = curl_exec($ch);
curl_close($ch);

Can you try without the active and changed data (you cannot alter active, and changed doesn’t exist), and format the date stopping at the second (e.g. 2024-02-23T16:38:04 not 2024-02-23T16:38:04+00:00). e.g.

$currentDateTime = date('Y-m-d\TH:i:s');
$data = [
  'disabled' => $currentDateTime,
];

Edit: I just tried it should work

<?php
$currentDateTime = date('Y-m-d\TH:i:s');
$data = [
    'disabled' => $currentDateTime
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-CSRF-Token: ' . $csrfToken,
    'Accept: application/json',
    'Content-Type: application/json',
    'Cookie: ' . $cookies
));
$response = curl_exec($ch);
curl_close($ch);
1 Like

-_- oh my goodness.
How blind you are at the end of a working day …

Thank you,it now works very fine!