2

I am new to Moodle, but I am setup site in local server. Created new courses, users into it. I want to enroll a patient to a specific course (created using admin side) through Javascript API. Are any options to enroll a user in a course. I couldn't find any Apis for enroll section

2 Answers 2

1

On old question but still in need of a real answer.

First you should ensure web services are turned on https://docs.moodle.org/401/en/Using_web_services

Then you can access the web api via a web client https://docs.moodle.org/dev/Creating_a_web_service_client

To see what calls are possible on your server, go to

https://yourserver.com/admin/webservice/documentation.php

If you look at for the keyword enrol you get a number of entries including enrol_manual_enrol_users:

General structure

list of ( 
  object {
    roleid int   //Role to assign to the user
    userid int   //The user that is going to be enrolled
    courseid int   //The course to enrol the user role in
    timestart int  Optional //Timestamp when the enrolment start
    timeend int  Optional //Timestamp when the enrolment end
    suspend int  Optional //set to 1 to suspend the enrolment
  } 
)

Where list of is of course an array or list of users

Using the rest interface, it's an old style PHP but Javascript data works if in the right format, e.g.:

enrolments[0][roleid]= int
enrolments[0][userid]= int
enrolments[0][courseid]= int
enrolments[0][timestart]= int
enrolments[0][timeend]= int
enrolments[0][suspend]= int

per user enrolment (incrementing the the enrolments[] for each enrolment)

0

Javascript API ? moodle uses PHP API and has also WebService API.

See this nice ws example : Using MOODLE create users and enroll them in courses via SQL

You could also call the WebService API via JS..

1
  • I have a course created using Admin Side, I want to enroll for a particular course using Js API. Web service creation and token sections are already made. But I couldn't find the solution for enrollment in a course Commented Aug 9, 2016 at 10:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.