I am trying to code login API from an external website to moodle. I don't know how to achieve it. Please guide me through. I want to create via REST webservice. Such that student logs in via that external website.
Ok, first of all, make sure you have well-configured moodle
Assuming that this refers to the latest version 3.5 here an example with javascript and axios (Axios is a promise based HTTP client for the browser and node.js)
axios
.get(YOUR_MOODLE_URL + "/login/token.php", {
params: {
username: "YOUR_FORM_USERNAME",
password: "YOUR_FORM_PASSWORD",
service: 'moodle_mobile_app'
}
})
.then((response) => {
console.log(response.data)
})
.catch((err) => console.error(error))
Or if you want to test it with the browser go to: YOUR_MOODLE_URL/login/token.php?username=YOUR_FORM_USERNAME&password=YOUR_FORM_PASSWORD&service=moodle_mobile_app
Replace YOUR_MOODLE_URL with the url of your moodle instalation and YOUR_FORM_USERNAME and YOUR_FORM_PASSWORD with valid credentials.
With this you get the user logged token to perform any action in moodle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With