Open phish108 opened 3 years ago
If one possesses the USERTOKEN
, a known vector for the token owner should be also known. The best thing to use is the email address. The email address is normally a standard attribute with moodle systems. In rare cases it is possible no email is stored for the user. In these cases the user should use the users full name, which is shown in Moodle's User Menu. This may yield multiple matches for common names.
The user information is obtained by searching the user using the function core_user_get_users_by_field
.
The API Call for getting the user id for a known vector such as the user's email
is:
/webservice/rest/server.php?wstoken=<USERTOKEN>&wsfunction=core_user_get_users_by_field&moodlewsrestformat=json&field=email&values[0]=user@example.com
Base URL: /webservice/rest/server.php?moodlewsrestformat=json&wstoken=${ USERTOKEN }
Attributes:
wsfunction
MUST BE core_user_get_users_by_field
field
the profile field to look up (ideally email
) values[0]
the exact lookup value. Without wildcards. The result is an array of user records or an empty array if no matches are found.
The search is successful if the any user is found. It MAY yield records for other users that match the lookup value.
The following attributes are only present if the USERTOKEN matches the selected user:
preferences
auth
theme
mailformat
lang
confirmed
username
Achtung: bei der Verwendung mit curl
muss die URL in Einfache Anführungszeichen gesetzt werden!
Ab moodle 4 ist es nicht mehr möglich alle Nutzer zu finden. So kann über die API für einen regulären Nutzer nicht mehr herausgefunden werden, ob ein anderer Nutzer existiert, solange es keine Peerverbindung (z.B. über einen Kurs) gibt.
A much smarter variant for bootstrapping is core_webservice_get_site_info
. It is parameterless and also reports the available functions for the user. This function only leaves out the user's email address, but this is OK, because Moodle uses the email only internally.
Many API Calls depend on the user id of the active user. The user id is not easy to find in Moodle. Is there an API call to get the user ID for the active user?