LMSouq
moodle-core Open

Moodle REST webservice: Problems sending an array as POST parameter

SO
soa
1 month ago
3 views
Problem Description
I'm using the Moodle REST webservice in combination with Qt. Login works, other functions with single parameters are working too. Now I want to use the function "core_user_update_users" which takes an array as parameter. The official documentation says: General Structure: list of ( object { id int //ID of the user username string Optional //Username policy is defined in Moodle security config. ... //more optional strings customfields Optional //User custom fields (also known as user profil fields) list of ( object { type string //The name of the custom field value string //The value of the custom field } )preferences Optional //User preferences list of ( object { type string //The name of the preference value string //The value of the preference } )} ) and: REST (POST parameters) users[0][id]= int users[0][username]= string //optional //many more parameters, but all optional like above <br/> So I thought this would be my HTTP Request: auto NetworkPostRequest = QNetworkRequest(QUrl("http://XXX.XXX.XXX.XXX/webservice/rest/server.php?wstoken=XXXXXXXXX&moodlewsrestformat=json&wsfunction=core_user_update_users" )); NetworkPostRequest.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded"); QByteArray Data; Data.append("users[0][id]=12"); Data.append("&users[0][firstname]=QtTestname"); this->NetworkAccessManager->put(NetworkPostRequest, Data); <br/> <br/> But I get the following debugmessage from moodle: { "debuginfo": "Missing required key in single structure: users", "errorcode": "invalidparameter", "exception": "invalid_parameter_exception", "message": "Invalid parameter value detected" } <br/> Obviously there is something wrong with Data, but I can't figure it out. Hopefully someone here can help.

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