MCGBra
MCGBra

Reputation: 240

Getting quizzes from Moodle

I'm trying to get Moodle's quizzes as JSON. I've already tried

http://desenvolvimento.imd.ufrn.br/qmmoodle/webservice/rest/server.php?wstoken=cf5a6639a4431341a40e7a75d8bb9cba&wsfunction=get_quizzes_by_course&moodlewsrestformat=json&course_id=2

To get all quizzes from a specific course. And

http://desenvolvimento.imd.ufrn.br/qmmoodle/webservice/rest/server.php?wstoken=cf5a6639a4431341a40e7a75d8bb9cba&wsfunction=get_quiz&moodlewsrestformat=json&quiz_id=3

To get a specific quiz.

I don't know what is wrong in my URL.

Thanks.

Upvotes: 2

Views: 3524

Answers (2)

joash
joash

Reputation: 2323

mod_quiz_get_quizzes_by_courses is the function that does the job. How to call it


https://yourmoodledomain/webservice/rest/server.php?moodlewsrestformat=json&courseids[0]=courseid&wsfunction=mod_quiz_get_quizzes_by_courses&wstoken=yourusertoken

Upvotes: 1

franzlorenzon
franzlorenzon

Reputation: 5943

I think that you are referring to this document. If you read closely, you'll notice that it's a proposal about how the quiz web service should be written.

In fact, when I tried your query, to get all quizzes from a course, I got:

{"exception":"dml_missing_record_exception","errorcode":"invalidrecord",
 "message":"Can not find data record in database table external_functions.",
 "debuginfo":"SELECT * FROM {external_functions}
              WHERE name = ?\n[array (\n  0 => 'get_quiz',\n)]"}

Moodle didn't found the external function get_quiz. That means... unfortunately, as of now, Moodle does not have a web service for quizzes.

If you feel adventurous, and what you need is just getting the quizzes, you could implement a web service to do that. The relevant moodle table about quizzes is mdl_quiz (for a full schema, look at this article), and here's the tutorial that shows how to implement it: Adding a web service to a plugin - Moodle Docs.

Upvotes: 2

Related Questions