LMSouq
moodle-core Open

How to create the right return function for a nested webservice in moodle

AD
adev
1 month ago
3 views
Problem Description
I'm trying to build the right response function in my moodle webservice. I printed the php structure of my json response: <!-- begin snippet: js hide: false --> <!-- language: lang-html --> [ { "name":"Quiz", "id":"1", "theme":"green", "quizzes":[ { "type":"single-select-item", "question":"Question example 1?", "options":[ "<p>answer1<br><\/p>", "<p>answer2<br><\/p>", "<p>answer3<br><\/p>", "<p>answer4<br><\/p>" ], "answer":"1" }, { "type":"single-select-item", "question":"<p>Question example 1?<br><\/p>", "options":[ "<p>answer1<br><\/p>", "<p>answer2<br><\/p>", "<p>answer3<br><\/p>", "<p>answer4<br><\/p>" ], "answer":"2" } ] } ] <!-- end snippet --> but I can't write the right return function for moodle webservices . I have written the return funtion as following return new external_multiple_structure( new external_single_structure( array( "name"=> new external_value(PARAM_TEXT, 'quiz name'), "id"=> new external_value(PARAM_TEXT, 'quiz id'), "theme"=> new external_value(PARAM_TEXT, 'quiz theme'), "quizzes" => new external_multiple_structure( new external_single_structure( array( "type" => new external_value(PARAM_TEXT, 'answer type'), "question" => new external_value(PARAM_TEXT, 'question'), "options" => new external_multiple_structure( new external_value(PARAM_TEXT, 'options') ), "answer" => new external_value(PARAM_TEXT, 'right answer') ) ) ) ) ) ); but I still receive the following exception. What's wrong in my return function? {"exception":"invalid_response_exception","errorcode":"invalidresponse","message":"Invalid response value detected"} any...

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