Skip to content

How to use the MoodleSync Command line Interface

Daniel-Schroeter edited this page Feb 1, 2023 · 3 revisions

The MoodleSync Command-line Interface (cli) offers the possibility to synchronize files to a Moodle-Platform via lines of text. This feature can be used to automate workflows via scripting.

To use the the command-line interface, the Moodle-Plugin "sync_service" must be installed and configured. Download- and installation-instructions can be found in its GitHub reporsitory here.

Note: Up to now it is only possible to upload files to Moodle and publish them inside a specified course and section.

Usage

To use the command-line interface, several parameters are needed:

  • Parameter 1: "c" or "course": With this parameter the moodle-course, in which a file should be published, is specified. The id of a course can be found inside the URL of a moodle-course opened in a browser (...id=XXXX...).
  • Parameter 2: "s" or "section": To specify the position of a file inside a course the section number, is needed. The section number can be found as the last digit of the sections URL or it can be determined by counting the sections of a course from the top to the bottom beginning with zero.
  • Parameter 3: "p" or "path": With the help of this parameter the file that should be uploaded and published could be determined. Please provide the path to it.
  • Parameter 4: "l" or "log-in": The command-line interface uses a config-file to retrieve necessary information about the Moodle-Platform and the user-specific token. This config-file should be created manually (see blow) and needs to be provided via its path.

In the following you can see a complete call, using the tool:

...\moodle-sync-cli.exe -c 1289 -s 3 -p "C:\Users\userA\Desktop\example.xlsx" - l "C:\Users\userA\Desktop\moodleData.properties"

Authentication

To be able to upload files you have to authenticate yourself to the Moodle platform. You have two options:

  1. Create a configuration file and protect it with corresponding file permissions. The content of the file should look like this:

    url = https://moodle.example.com
    token = 640ab2bae07bedc4c163f679a746f7ab7fb5d1fa
    
    • url specifies the Moodle platfrom URL
    • token specifies the access token created for your specific user account, so you don't have to provide your user id and password
  2. Provide authentication data via environment variables which have the same meaning as described above:

    • MOODLE_SYNC_URL specifies the Moodle platfrom URL
    • MOODLE_SYNC_TOKEN specifies the access token

Clone this wiki locally