Johnathan Stowers
Johnathan Stowers

Reputation: 1

Calling the Moodle Rest-API

I am unclear on how to make any API calls to my Moodle web-server from my Node.JS LMS. I already setup the Moodle server and created the user with the correct role, but I don't know how to call it from my project. I'm currently just trying to extract course data from a course with an ID of 1 using core_course_get_contents. I am currently just working in javascript.

I tried making a fetch call from the client, but I was just met with various errors. I decided to use the server I'm working on as a proxy to get around the CORS limitations, but now I'm getting certificate errors or a bad JSON error.

Upvotes: 0

Views: 472

Answers (1)

Igor
Igor

Reputation: 1121

You can create an API at Moodle. It calls Web-Services. To create and enable it follow these steps:

  1. Enable REST protocol /admin/settings.php?section=webserviceprotocols
  2. Create new service /admin/webservice/service.php?id=0
  3. Create a token /admin/webservice/tokens.php?action=create and attach it to Web Service from step 2
  4. Go to External Web Services list at /admin/settings.php?section=externalservices and add an external function to a needle service from step 2. You can use core Moodle external functions or create an own one.
  5. Create a request with params. Read here how

API Manager Plugin

Yes, this is a quest, but you can use local_wsmanager plugin to manage Moodle Web-Services/APIs from one place.

Upvotes: 0

Related Questions