LMSouq
moodle-core Open

How to create a user in the Moodle Rest WS using the Python Requests module?

AR
arthas_dk
1 month ago
3 views
Problem Description
I'm trying to create a user using the Moodle Webservices - Rest Server, but I'm stuck at the validation of the params :S My code is the following: import requests token = 'TOKENNUMBER' function = 'core_user_create_users' url = 'http://localhost/webservice/rest/server.php?wstoken={0}&wsfunction={1}&moodlewsformat=json'.format(token,function) user1 = {'email': 'email@local.host','firstname': 'firstname', 'lastname': 'lastname', 'createpassword': 1, 'username': 'username'} Then, I try to post the data (two different ways): requests.post(url,data={'users': user1}) requests.post(url,data={'users': [user1,]}) And moodle keeping return the error: Only arrays accepted. The bad value is: \'username\'</DEBUGINFO> In the documentation (available from the own moodle), its stated: Argumentos users (Obrigatório) Estrutura geral list of ( object { username string //Username policy is defined in Moodle security config. password string Opcional //Plain text password consisting of any characters createpassword int Opcional //True if password should be created and mailed to user. firstname string //The first name(s) of the user lastname string //The family name of the user email string //A valid and unique email address auth string Padrão para "manual" //Auth plugins include manual, ldap, imap, etc idnumber string Padrão para "" //An arbitrary ID code number perhaps from the institution lang string Padrão para "pt_br" //Language code such as "en", must exist on server calendartype string Padrão para "gregorian" //Calendar type such as "gregorian", must exist on server theme string Opcional //Theme name such as "standard", must exist on server timezone string Opcional //Timezone code such as Australia/Perth, or 99 for default mailformat int Opcional //Mail format code is 0 for plain text, 1 for HTML etc description string Opcional //User profile description, no HTML city string Opcional //Home city of the user country string Opcional //Home country code of the user, such as AU or CZ firstnamephonetic string Opcional //The first name(s) phonetically of the user lastnamephonetic string Opcional //The family name phonetically of the user middlename string Opcional //The middle name of the user alternatename string Opcional //The alternate name of the user preferences Opcional //User preferences list of ( object { type string //The name of the preference value string //The value of the preference } )customfields Opcional //User custom fields (also known as user profil fields) list of ( object { type string //The name of the custom field value string...

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