How to use moodle APIs to create quiz and questions

How to use moodle APIs to create quiz and questions

by Michelin Lin -
Number of replies: 4
Hi guys, I am currently working on an LTI on moodle. I am writing API calls for one button. If the button is clicked, the written API calls create a new practice quiz with example questions. 

The order I plan to go with is:    get authentication/token,   create quiz, create question under the quiz.  

For now, I have used   mysite/login/token.php?username=******&password=*****&service=verity_lti_create_quiz     to get the token, and then I plan to use that token to create quiz and questions, but somehow I am not able to find the right api to use not the parameters to include. I only find "core_course_get_courses".   Noted, I will not be able to use php code to make the call, only pure URL.

Also, I was writing the same API thing for canvas and blackboard LTI. For those two, the token needs to be refreshed when expired, do Moodle token expire?

Many thanks

Average of ratings: -
In reply to Michelin Lin

Re: How to use moodle APIs to create quiz and questions

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Michelin,

there are no API functions for this, you'd need to develop a Moodle plugin including new Web SErvices if you want to achieve this

Most of the existing API functions in Moodle core are mostly for students (to allow them to attempt a quiz, take a choice, post in a forum, etc...)
Average of ratings: Useful (1)
In reply to Michelin Lin

Re: How to use moodle APIs to create quiz and questions

by Stoo Sepp -
Moodle is incredibly limited in the API arena - I wanted to develop something just to update my module or 'section' names and that doesn't exist. You can't even pull student log data like you can in other LMS's.
Overall, Moodle is built as a front-end web app first (as it was built over 20 years ago at its core, which makes sense considering...). Most modern web apps, and other LMSs are built for APIs from the ground up and it would take a massive rewrite of Moodle's base code to catch it up to other LMSs at this point, which I *hope* is in the works.
In reply to Stoo Sepp

Re: How to use moodle APIs to create quiz and questions

by Rodrigo Martins -
I'm a bit disappointed we're not able to create quizzes via API.

However, renaming sections is possible. I strugled with it a bit but I found out we can use 'core_update_inplace_editable' to do it. 

You can use the following parameters to call the API:

wstoken: 'Your token'
moodlewsrestformat: 'json'
wsfunction: 'core_update_inplace_editable'
component: 'format_topics'
itemtype: 'sectionname'
itemid: 'your section ID'
value: 'New name'

You can get the section id by calling the 'core_course_get_contents' function.

In reply to Rodrigo Martins

Re: How to use moodle APIs to create quiz and questions

by Stoo Sepp -
Thanks for this - Sadly, I don't have access to that, because as an instructor at my institution, I only have access to mobile_app REST API functions and many of the core functions are limited access. Good luck in your future API endeavours!