LMSouq
moodle-core Open

Suspend a Moodle user by using Web service API functions

PE
Pestana
1 month ago
3 views
Problem Description
I am trying to suspend a user in Moodle by using Moodle's [Web service API functions][1] in PHP. I can change user fields like firstname, but I am not capable to suspend the user. It always returns "null". Here is my code: <?php $serverurl = "http://localhost/web/moodle/webservice/rest/server.php?wstoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&wsfunction=core_user_update_users&moodlewsrestformat=json"; $params = "users[0][id]=4&users[0][preferences][0][type]=suspended&users[0][preferences][0][value]=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $serverurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $response = curl_exec($ch); print_r($response); curl_close($ch); ?> [1]: https://docs.moodle.org/dev/Web_service_API_functions

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base