Skip to content

Write tools

36 tools that change data or need write mode: 26 with scope write and 10 with scope admin. Scope write (or admin) and capability local/mcpserver:write (local/mcpserver:admin for admin tools). Write mode must be on and the tool enabled; otherwise write tools are not listed. See Enabling write mode. Account tools (create_user, create_users, update_user, suspend_user, unsuspend_user) and site policy tools (set_site_policy_handler, create_policy, update_policy, list_policies, get_policy_acceptances) need the admin scope. list_policies and get_policy_acceptances only read, but they are admin tools and need write mode too. Each tool also checks the Moodle capability below.

Most write tools accept dryRun. delete_activity, delete_section and grade_submission are dry runs by default; see Grading with dryRun. Dates accept YYYY-MM-DD (midnight in the user's timezone), an ISO 8601 datetime with an offset, or a Unix timestamp.

Courses and activities

create_course

Create a blank course, or queue a background copy when templateCourseId is set. A template copy returns a task id and status immediately; poll get_task_status. Choose the category with categoryId, categoryName or categoryIdnumber. Pass dryRun true to validate without creating a course or queueing a task.

Parameter Type Required Default Description
fullName string yes — Course full name. (max. 254)
shortName string yes — Unique course short name. (max. 255)
categoryId integer no 1 Category id. Defaults to 1. Ignored when categoryIdnumber or categoryName is set.
categoryName string no — Category name. If several match, the error lists them. Use list_categories. (max. 255)
categoryIdnumber string no — Category idnumber. Preferred over categoryName and categoryId. (max. 100)
summary string no "" Course summary HTML.
format string no "topics" Enabled course format.
visible boolean no true Whether the course is visible to students.
numSections integer no 1 Number of sections for a blank course. Ignored when copying a template. (0–52)
startDate integer or string no — Course start. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
endDate integer or string no — Course end. 0 means no end date. On a weekly course, sending this date keeps it instead of calculating it from the number of sections. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
templateCourseId integer no — Course id to copy. Activities are copied. Users are not copied unless includeUserData is true.
includeUserData boolean no false Copy enrolments and user data from the template. Requires the backup user-info capability.
dryRun boolean no false When true, check permissions and names but do not create a course or queue a copy.

Returns: courseId, shortName, fullName, url, taskId, status, queued, dryRun.

Scope: write. Moodle permissions: moodle/course:create in the category; a copy also needs moodle/backup:backupcourse and moodle/backup:backuptargetimport (moodle/backup:userinfo with user data).

Example arguments:

{"fullName": "Statistics 102", "shortName": "STAT102", "categoryIdnumber": "SCI", "dryRun": true}

add_section

Add a section at the end of a course and optionally set its name and summary.

Parameter Type Required Default Description
courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
name string no — Section name. Omit to keep the format default. (max. 255)
summary string no "" Section summary HTML.

Returns: courseId, section, name.

Scope: write. Moodle permissions: moodle/course:update.

Example arguments:

{"courseId": 42, "name": "Week 5"}

add_activity

Add a page, url, label, resource, assign, quiz, forum or choice. Each field says which types it applies to, for example [assign] or [url]. A field sent for another type is an error. Assignments accept dates, a maximum grade, submission types and a basic rubric. A resource takes fileUrl or fileBase64 (2 MiB maximum). A label or a page can take images (jpg, png, gif, webp or svg, fileBase64 plus fileName, or an https fileUrl); they are stored in the intro or content area and the HTML uses @@PLUGINFILE@@, never a data URI. Completion fields (view, submit, grade, passing grade, forum posts and the expected date) are accepted only when the module supports them. settings is any other field from the module's form; unknown keys are rejected. A choice accepts settings.option (a list of texts), settings.limit, allowupdate and showresults (0 does not publish the results); completionSubmit marks it complete when the student chooses. Use get_activity_settings to list the form fields.

Parameter Type Required Default Description
courseId integer one of courseId / courseShortname — [all] Moodle course id. Alternative to courseShortname. Send only one of the two.
courseShortname string one of courseId / courseShortname — [all] Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
section integer yes — [all] Section number. Section 0 is the general section.
type string yes — [all] Activity type. Values: page, url, label, assign, quiz, forum, resource, choice.
name string no — [all] Activity name. For a label this may be omitted and the intro is used. (max. 255)
intro string no "" [all] Description HTML. This is the body of a label.
content string no — [page, label] Page HTML content. Also used as the label body when intro is empty.
images array no — [page, label] Images for a label or a page. Each one is fileBase64 plus fileName, or an https fileUrl, and area intro or content. Stored in the file area and referenced as @@PLUGINFILE@@. (up to 10)
externalUrl string no — [url] External URL. (max. 1333)
dueDate integer or string no — [assign] Assignment due date. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
timeOpen integer or string no — [quiz] Quiz open time. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
timeClose integer or string no — [quiz] Quiz close time. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
grade integer no — [assign, quiz] Maximum grade. (0–100000)
forumType string no — [forum] Forum type. Defaults to general. Values: general, eachuser, single, qanda, blog, news.
visible boolean no — [all] Whether the activity is visible. Defaults to true.
allowSubmissionsFromDate integer or string no — [assign] Assignment open date. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
cutoffDate integer or string no — [assign] Assignment cut-off date. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
gradingDueDate integer or string no — [assign] Date by which grading should be completed. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
submissionTypes array no — [assign] Submission plugins: file and/or onlinetext. (up to 2)
rubric array no — [assign] Optional rubric. Each criterion has a description and at least two levels. (up to 20)
fileName string no — [resource] File name. (max. 255)
fileUrl string no — [resource] Public http(s) URL of the file. (max. 1333)
fileBase64 string no — [resource] Base64 contents of the file. Maximum 2 MiB decoded.
timeLimit integer no — [quiz] Time limit in seconds. 0 means no limit.
attempts integer no — [quiz] Attempts allowed. 0 means unlimited. (0–10)
gradeMethod string no — [quiz] How the grade is calculated from attempts. Values: highest, average, first, last.
navMethod string no — [quiz] Navigation: free or sequential. Values: free, sequential.
questionsPerPage integer no — [quiz] Questions per page. 0 means all on one page. (0–50)
shuffleAnswers boolean no — [quiz] Shuffle the answers.
review string no — [quiz] When students may review the attempt. Values: immediately, later, afterclose, never.
settings object no — [all] Module form options, using the form field names. Unknown keys are rejected and the error lists the valid ones. Includes visible, cmidnumber, groupmode, completion and availabilityconditionsjson.
completionView boolean no — [all] Require the student to view the activity. The module must support completion views.
completionSubmit boolean no — [all] Require a submission or a choice. Only modules with the completionsubmit rule, such as assign or choice.
completionUseGrade boolean no — [all] Require a grade. The module must have a grade.
completionPassGrade boolean no — [all] Require a passing grade. Send gradePass as well. The module must have a grade.
gradePass number no — [all] Minimum grade to pass. Required when completionPassGrade is true, and not above the maximum grade.
completionPosts integer no — [all] Posts the student must publish. Only modules that define completionposts, such as forum. 0 clears it. (0–1000)
completionDiscussions integer no — [all] Discussions the student must start. Only modules that define completiondiscussions. 0 clears it. (0–1000)
completionReplies integer no — [all] Replies the student must post. Only modules that define completionreplies. 0 clears it. (0–1000)
completionExpected integer or string no — [all] Date the activity is expected to be completed. (date)

Fields of each item in rubric:

  • description* (string): [assign] What this criterion assesses. (max. 1000)
  • levels* (array): [assign] Levels for this criterion, lowest score first. (up to 10) → definition, score

    * = required.

    Returns: cmid, courseId, type, name.

    Scope: write. Moodle permissions: moodle/course:manageactivities and mod/<type>:addinstance (moodle/grade:managegradingforms for a rubric).

    Example arguments:

    {"courseId": 42, "section": 1, "type": "assign", "name": "Submit the field notes", "dueDate": "2026-11-20", "submissionTypes": ["file"]}
    

    update_activity

    Update an existing page, url, label, resource, assign, quiz, forum or choice. It also takes images for a page or label, completion fields and settings (omitted keys stay as they are). Only the fields you send are changed. Each field says which types it applies to, for example [assign] or [url]. A field that does not apply to this activity is an error.

    Parameter Type Required Default Description
    cmid integer yes — [all] Course module id.
    name string no — [all] New activity name. (max. 255)
    intro string no — [all] New description HTML.
    content string no — [page, label] New page HTML content.
    images array no — [page, label] Images for a label or a page. Each one is fileBase64 plus fileName, or an https fileUrl, and area intro or content. Stored in the file area and referenced as @@PLUGINFILE@@. (up to 10)
    externalUrl string no — [url] External URL. (max. 1333)
    dueDate integer or string no — [assign] Assignment due date. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
    timeOpen integer or string no — [quiz] Quiz open time. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
    timeClose integer or string no — [quiz] Quiz close time. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
    grade integer no — [assign, quiz] Maximum grade. (0–100000)
    forumType string no — [forum] Forum type. Values: general, eachuser, single, qanda, blog, news.
    visible boolean no — [all] Whether the activity is visible.
    settings object no — [all] Module form options to change, using the form field names. Unknown keys are rejected and the error lists the valid ones. Omitted keys stay as they are.
    completionView boolean no — [all] Require the student to view the activity. The module must support completion views.
    completionSubmit boolean no — [all] Require a submission or a choice. Only modules with the completionsubmit rule, such as assign or choice.
    completionUseGrade boolean no — [all] Require a grade. The module must have a grade.
    completionPassGrade boolean no — [all] Require a passing grade. Send gradePass as well. The module must have a grade.
    gradePass number no — [all] Minimum grade to pass. Required when completionPassGrade is true, and not above the maximum grade.
    completionPosts integer no — [all] Posts the student must publish. Only modules that define completionposts, such as forum. 0 clears it. (0–1000)
    completionDiscussions integer no — [all] Discussions the student must start. Only modules that define completiondiscussions. 0 clears it. (0–1000)
    completionReplies integer no — [all] Replies the student must post. Only modules that define completionreplies. 0 clears it. (0–1000)
    completionExpected integer or string no — [all] Date the activity is expected to be completed. (date)

    Returns: cmid, instanceId, courseId, type, name, section, visible, url.

    Scope: write. Moodle permissions: Moodle's normal activity update check (moodle/course:manageactivities); moodle/course:activityvisibility to change visible.

    Example arguments:

    {"cmid": 314, "dueDate": "2026-11-27T23:59:00+01:00"}
    

    set_visibility

    Show or hide a course (courseId or courseShortname), a section (that course and section) or an activity (cmid).

    Parameter Type Required Default Description
    target string yes — What to show or hide. Values: course, section, activity.
    visible boolean yes — True to show, false to hide.
    courseId integer no — Moodle course id. Alternative to courseShortname. Send only one of the two.
    courseShortname string no — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
    section integer no — Section number when target is section.
    cmid integer no — Course module id when target is activity.

    Returns: target, visible.

    Scope: write. Moodle permissions: moodle/course:visibility, moodle/course:sectionvisibility or moodle/course:activityvisibility, depending on the target.

    Example arguments:

    {"target": "activity", "cmid": 314, "visible": false}
    

    delete_activity

    Delete an activity. Dry run unless dryRun is false and confirm is true.

    Parameter Type Required Default Description
    cmid integer yes — Course module id.
    dryRun boolean no true When true (the default), do not delete. Return what would be deleted.
    confirm boolean no false Must be true together with dryRun false to delete the activity.

    Returns: dryRun, deleted, confirmationRequired, target.

    Scope: write. Moodle permissions: moodle/course:manageactivities.

    Example arguments:

    {"cmid": 314}
    

    delete_section

    Delete a section and its activities. Section 0 cannot be deleted. Dry run unless confirmed.

    Parameter Type Required Default Description
    courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
    courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
    section integer yes — Section number. Section 0 cannot be deleted.
    dryRun boolean no true When true (the default), do not delete. Return what would be deleted.
    confirm boolean no false Must be true together with dryRun false to delete the section.

    Returns: dryRun, deleted, confirmationRequired, target.

    Scope: write. Moodle permissions: moodle/course:update.

    Example arguments:

    {"courseId": 42, "section": 5}
    

    build_course

    Build a course from sections, activities and quiz questions. Returns a task id immediately. Poll get_task_status. dryRun true validates and returns the plan without creating anything. Choose the category with categoryId, categoryName or categoryIdnumber. Pass courseId or courseShortname to build inside a course the user can already edit. shortName is the name of a new course, not another way to pick an existing one.

    Parameter Type Required Default Description
    dryRun boolean no false Validate and return the plan without creating anything.
    courseId integer no — Build inside this course instead of creating one. Alternative to courseShortname. Send only one of the two.
    courseShortname string no — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
    fullName string no — (max. 254)
    shortName string no — (max. 255)
    categoryId integer no 1 Category id. Ignored when categoryIdnumber or categoryName is set.
    categoryName string no — Category name. Use list_categories when several categories share it. (max. 255)
    categoryIdnumber string no — Category idnumber. Preferred over categoryName and categoryId. (max. 100)
    summary string no ""
    format string no "topics" Enabled course format.
    startDate integer or string no — Course start. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
    endDate integer or string no — Course end. 0 means no end date. On a weekly course, sending this date keeps it instead of calculating it from the number of sections. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
    visible boolean no true
    sections array no [] (up to 52)

    Fields of each item in sections:

    • number (integer): (0–52)
    • name (string): (max. 255)
    • summary (string)
    • activities (array): (up to 40) → type, name, intro, content, externalUrl, visible, dueDate, allowSubmissionsFromDate, cutoffDate, grade, submissionTypes, rubric, fileName, fileUrl, fileBase64, timeOpen, timeClose, timeLimit, attempts, gradeMethod, navMethod, questionsPerPage, shuffleAnswers, review, forumType, category, questions, gift, xml

      * = required.

      Returns: dryRun, taskId, status, course, sections[].

      Scope: write. Moodle permissions: New course: moodle/course:create in the category; existing course: moodle/course:manageactivities.

      Example arguments:

      {"dryRun": true, "fullName": "Intro to R", "shortName": "R101", "sections": [{"number": 1, "name": "Getting started", "activities": [{"type": "page", "name": "Install R", "content": "<p>Download R from CRAN.</p>"}]}]}
      

      update_course

      Update a course. Only the fields you send are changed. The image is fileBase64 plus fileName, or an https fileUrl, with the same checks as set_course_image. Saved with core update_course(). The site home cannot be updated.

      Parameter Type Required Default Description
      courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
      courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
      fullName string no — New course full name. (max. 254)
      shortName string no — New unique short name. (max. 255)
      summary string no — New summary HTML. It is cleaned before saving.
      startDate integer or string no — New course start. (date)
      endDate integer or string no — New course end. 0 means no end date. On a weekly course this turns off the calculated end date. (date)
      visible boolean no — Whether students can see the course.
      format string no — Enabled course format, e.g. topics, weeks.
      formatOptions object no — Options of the format being saved: numsections, hiddensections, coursedisplay, automaticenddate. numsections adds any missing sections and does not delete existing ones.
      enableCompletion boolean no — Turn completion tracking on or off. Enabling it needs the site completion setting.
      showGrades boolean no — Whether students can see the gradebook.
      showReports boolean no — Whether students can see their own activity reports.
      lang string no — Forced course language (an installed language), or an empty string for no force.
      groupMode integer no — 0 no groups, 1 separate groups, 2 visible groups.
      groupModeForce boolean no — Force the course group mode on every activity.
      fileName string no — File name with an image extension. Required with fileBase64. With fileUrl the URL path is used when this is omitted. (max. 255)
      fileBase64 string no — Base64 image. Maximum 2 MiB decoded. Do not send this and fileUrl together.
      fileUrl string no — https URL of the image. Moodle cURL refuses blocked hosts and ports. (max. 1333)

      Returns: courseId, fullName, shortName, summary, startDate, endDate, visible, format, enableCompletion, showGrades, showReports, lang, groupMode, groupModeForce, sectionCount, formatOptions.

      Scope: write. Moodle permissions: Per field: moodle/course:changefullname (fullName), moodle/course:changeshortname (shortName), moodle/course:changesummary (summary and the image), moodle/course:visibility (visible), moodle/course:setforcedlanguage (lang); everything else moodle/course:update.

      Example arguments:

      {"courseId": 42, "endDate": "2027-06-30", "formatOptions": {"numsections": 12}}
      

      set_course_image

      Set the course image shown on My courses and the course list. Send fileBase64 and fileName, or an https fileUrl. The file must be a jpg, png, gif, webp or svg image allowed by the site course image extensions, and at most 2 MiB. An https URL is downloaded with Moodle cURL, which blocks the hosts and ports configured under HTTP security, and redirects are not followed (SSRF protection). The previous image is replaced and the course caches are purged.

      Parameter Type Required Default Description
      courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
      courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
      fileName string no — File name with an image extension. Required with fileBase64. With fileUrl the URL path is used when this is omitted. (max. 255)
      fileBase64 string no — Base64 image. Maximum 2 MiB decoded. Do not send this and fileUrl together.
      fileUrl string no — https URL of the image. Moodle cURL refuses blocked hosts and ports. (max. 1333)

      Returns: courseId, fileName, bytes, url.

      Scope: write. Moodle permissions: moodle/course:update.

      Example arguments:

      {"courseId": 42, "fileUrl": "https://example.org/cover.png"}
      

      set_course_completion

      Turn completion tracking on or off for a course. Shortcut for update_course with enableCompletion. The site completion setting must be on before a course can enable it. Activity completion needs this first.

      Parameter Type Required Default Description
      courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
      courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
      enabled boolean yes — True to enable completion tracking for the course, false to disable it.

      Returns: courseId, enabled.

      Scope: write. Moodle permissions: moodle/course:update.

      Example arguments:

      {"courseId": 42, "enabled": true}
      

      set_availability

      Set the restrict-access rules for an activity (cmid) or a section (course plus section). applyTo (sections, activities or all) uses the same tree on every section and/or activity in the course: it merges the tree with AND into the restriction already stored and skips a condition already there. excludeCmids skips those activities; an activity named by a completion condition is skipped as well, so the condition does not lock the activity it depends on. availability is a core_availability tree: op is & (AND) or | (OR), nested trees allowed, and c is the list of conditions. An AND root needs showc, an OR root needs show. Conditions: completion of another activity (type: completion, cm, e 1 completed or 2 passed), a date (type: date, d >= or <, t Unix timestamp) or a grade (type: grade, id, optional min and max). The tree is checked with core_availability\tree before saving. An empty condition list removes the restriction from one activity or section; it is rejected with applyTo.

      Parameter Type Required Default Description
      target string no — activity uses cmid; section uses the course and the section number. Values: activity, section.
      cmid integer for activity — Course module id when target is activity.
      courseId integer for section / applyTo — Moodle course id when target is section, or when applyTo is set. Alternative to courseShortname.
      courseShortname string for section / applyTo — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
      section integer for section — Section number when target is section. Section 0 is the general section.
      applyTo string no — Apply one tree to every section, every activity, or both. Do not send target as well. Values: sections, activities, all.
      excludeCmids array no — Activities to leave unchanged when applyTo is set.
      availability object yes — core_availability tree (op, c, showc or show).

      Returns: target, courseId, cmid, section, availability, applyTo, updated, unchanged, excluded.

      Scope: write. Moodle permissions: Activities moodle/course:manageactivities; sections moodle/course:update.

      Example arguments:

      {"courseId": 42, "applyTo": "activities", "availability": {"op": "&", "showc": [true], "c": [{"type": "date", "d": ">=", "t": 1793487600}]}}
      

      Quizzes and questions

      create_quiz

      Create a quiz in a section. dryRun true checks the course and returns the plan without saving. Requires moodle/course:manageactivities and mod/quiz:addinstance.

      Parameter Type Required Default Description
      courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
      courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
      section integer yes — Section number.
      name string yes — (max. 255)
      intro string no ""
      timeOpen integer or string no — Quiz open time. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
      timeClose integer or string no — Quiz close time. A date without a time (YYYY-MM-DD) is midnight in your timezone. You can also send an ISO 8601 datetime with an offset, or a Unix timestamp. (date)
      timeLimit integer no — Seconds. 0 means no limit.
      attempts integer no — 0 means unlimited. (0–10)
      grade integer no 10 (0–100000)
      gradeMethod string no — Values: highest, average, first, last.
      navMethod string no — Values: free, sequential.
      questionsPerPage integer no — (0–50)
      shuffleAnswers boolean no —
      review string no — Values: immediately, later, afterclose, never.
      visible boolean no —
      dryRun boolean no false When true, check the course and section and do not create the quiz.

      Returns: dryRun, cmid, courseId, section, name, url.

      Scope: write. Moodle permissions: moodle/course:manageactivities and mod/quiz:addinstance.

      Example arguments:

      {"courseId": 42, "section": 2, "name": "Check your understanding", "attempts": 2, "review": "afterclose"}
      

      add_quiz_questions

      Create questions in the course question bank and add them to a quiz. Requires mod/quiz:manage and moodle/question:add. Types: multichoice, truefalse, shortanswer, numerical, match, essay.

      Parameter Type Required Default Description
      cmid integer yes — Quiz course module id.
      category string no — Question bank category name. Omit for the default category. (max. 254)
      questions array yes — (up to 50)

      Fields of each item in questions:

      • type* (string): Values: multichoice, truefalse, shortanswer, numerical, match, essay.
      • name* (string): (max. 255)
      • text* (string)
      • mark (number)
      • correct (boolean)
      • caseSensitive (boolean)
      • answer (number)
      • tolerance (number)
      • answers (array): (up to 20)
      • choices (array): (up to 20) → text*, correct
      • pairs (array): (up to 20) → question, answer

        * = required.

        Returns: cmid, categoryId, questions[].

        Scope: write. Moodle permissions: mod/quiz:manage and moodle/question:add (moodle/question:managecategory to create a category).

        Example arguments:

        {"cmid": 316, "questions": [{"type": "truefalse", "name": "Mean vs median", "text": "The median is less sensitive to outliers than the mean.", "correct": true}, {"type": "multichoice", "name": "Spread", "text": "Which measure describes spread?", "choices": [{"text": "Standard deviation", "correct": true}, {"text": "Mode"}]}]}
        

        import_questions

        Import GIFT or Moodle XML into a question-bank category using the core importers. Optionally add the new questions to a quiz. Requires moodle/question:add.

        Parameter Type Required Default Description
        courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
        courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
        format string yes — Enabled question import format. Values: gift, xml.
        content string yes —
        category string no — (max. 254)
        cmid integer no — Quiz to add the imported questions to.

        Returns: courseId, categoryId, questionIds[], added.

        Scope: write. Moodle permissions: moodle/question:add (mod/quiz:manage to add them to a quiz).

        Example arguments:

        {"courseId": 42, "format": "gift", "content": "::Q1:: 2 + 2 = {=4 ~3 ~5}", "cmid": 316}
        

        Grading

        grade_submission

        Set the grade and feedback comment on one student's assignment. When the assignment uses a rubric, send a levelId for every criterion. dryRun defaults to true and changes nothing. notify defaults to false. Identify the student with userId, username or email, and only one of them. Requires the write scope, write tools enabled, and mod/assign:grade. The student must be enrolled. A group assignment applies the grade to the whole group.

        Parameter Type Required Default Description
        cmid integer yes — Assignment course module id.
        grade number no — Point grade from 0 to the assignment maximum. Required unless the assignment uses a rubric.
        comment string no — Feedback comment shown to the student. Omit it to leave the current comment unchanged. (max. 10000)
        criteria array no — Rubric choices. Required when the assignment uses a rubric, one level per criterion. (up to 30)
        notify boolean no false When true, Moodle may email the student about the grade. Defaults to false.
        dryRun boolean no true When true, validate and describe the grade without saving. Defaults to true.
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)

        Fields of each item in criteria:

        • criterionId* (integer): Criterion id from get_submission.
        • levelId* (integer): Level id to select for that criterion.
        • remark (string): Optional comment for this criterion. (max. 2000)

        * = required.

        Returns: cmid, courseId, name, userId, fullName, status, submitted, attempt, timeModified, onlineText, files[], grade, gradeMax, gradeTime, comment, grading, dryRun, saved, notified, proposed.

        Scope: write. Moodle permissions: Scope write, write tools enabled and mod/assign:grade.

        Example arguments:

        {"cmid": 314, "username": "ada", "grade": 8.5, "comment": "Clear method; check the units in part 2."}
        

        Enrolment, roles and groups

        enrol_user

        Enrol a user in a course with manual enrolment. Provide userId, username or email. The role defaults to student. dryRun true checks the enrolment and does not save it.

        Parameter Type Required Default Description
        courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
        courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        role string no "student" Role shortname. The list is the roles that exist on this site. (max. 100)
        dryRun boolean no false When true, check the user and role and do not enrol anyone.

        Returns: courseId, userId, role, enrolled, alreadyEnrolled, dryRun.

        Scope: write. Moodle permissions: enrol/manual:enrol.

        Example arguments:

        {"courseId": 42, "email": "[email protected]", "role": "student"}
        

        unenrol_user

        Remove a user's manual enrolment from a course. Other enrolment methods are left in place. Identify the user with userId, username or email. dryRun true changes nothing. Requires the write scope and enrol/manual:unenrol.

        Parameter Type Required Default Description
        courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
        courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        dryRun boolean no false When true, check the enrolment and do not remove it.

        Returns: courseId, userId, removed, stillEnrolled, dryRun.

        Scope: write. Moodle permissions: enrol/manual:unenrol.

        Example arguments:

        {"courseId": 42, "username": "ada", "dryRun": true}
        

        set_user_role

        Assign or remove a role in a course. This does not enrol the user; use enrol_user for manual enrolment. A role that comes from enrolment is removed with unenrol_user. action is assign or remove. dryRun true changes nothing. Requires the write scope and moodle/role:assign.

        Parameter Type Required Default Description
        courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
        courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        role string yes — Role shortname, such as student or editingteacher. (max. 100)
        action string yes — assign adds the role. remove takes away a manual role assignment. Values: assign, remove.
        dryRun boolean no false When true, check the role and do not change it.

        Returns: courseId, userId, role, action, dryRun.

        Scope: write. Moodle permissions: moodle/role:assign.

        Example arguments:

        {"courseId": 42, "username": "ada", "role": "teacher", "action": "assign"}
        

        create_group

        Create a group in a course.

        Parameter Type Required Default Description
        courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
        courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
        name string yes — Group name. (max. 254)
        description string no "" Group description HTML.

        Returns: groupId, courseId, name.

        Scope: write. Moodle permissions: moodle/course:managegroups.

        Example arguments:

        {"courseId": 42, "name": "Group A"}
        

        add_group_members

        Add enrolled users to a group. Each member is userId, username or email. dryRun true changes nothing. Requires the write scope and moodle/course:managegroups.

        Parameter Type Required Default Description
        courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
        courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
        groupId integer yes — Group id in that course.
        members array yes — Add these people. Each item has userId, username or email. (up to 50)
        dryRun boolean no false When true, check the group and do not change membership.

        Fields of each item in members:

        • userId (integer): One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        • username (string): One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        • email (string): One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)

        * = required.

        Returns: courseId, groupId, dryRun, members[].

        Scope: write. Moodle permissions: moodle/course:managegroups.

        Example arguments:

        {"courseId": 42, "groupId": 9, "members": [{"username": "ada"}, {"email": "[email protected]"}]}
        

        remove_group_members

        Remove users from a group. Each member is userId, username or email. dryRun true changes nothing. Requires the write scope and moodle/course:managegroups.

        Parameter Type Required Default Description
        courseId integer one of courseId / courseShortname — Moodle course id. Alternative to courseShortname. Send only one of the two.
        courseShortname string one of courseId / courseShortname — Exact course short name. Alternative to courseId for the same course. Send only one of the two. (max. 255)
        groupId integer yes — Group id in that course.
        members array yes — Remove these people. Each item has userId, username or email. (up to 50)
        dryRun boolean no false When true, check the group and do not change membership.

        Fields of each item in members:

        • userId (integer): One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        • username (string): One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        • email (string): One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)

        * = required.

        Returns: courseId, groupId, dryRun, members[].

        Scope: write. Moodle permissions: moodle/course:managegroups.

        Example arguments:

        {"courseId": 42, "groupId": 9, "members": [{"userId": 57}]}
        

        Forums and messaging

        create_forum_discussion

        Start a forum discussion, including in the announcements (news) forum. Pass cmid or forumId, not both. The message is HTML and is cleaned before it is stored. Group mode is respected. The post is queued for the normal forum email.

        Parameter Type Required Default Description
        cmid integer one of cmid / forumId — Forum course module id.
        forumId integer one of cmid / forumId — Forum instance id.
        subject string yes — Discussion subject. (max. 255)
        message string yes — Discussion message as HTML.
        groupId integer no — Group id when the forum uses groups. Omit to use the caller's current group.
        pinned boolean no false Pin the discussion.

        Returns: discussionId, postId, forumId, cmid, courseId, url, pinned.

        Scope: write. Moodle permissions: mod/forum:addnews in the announcements forum, mod/forum:startdiscussion elsewhere; mod/forum:pindiscussions for pinned.

        Example arguments:

        {"cmid": 120, "subject": "Week 3 is open", "message": "<p>The materials for week 3 are ready.</p>"}
        

        reply_forum_post

        Reply to a forum post. The message is HTML and is cleaned before it is stored. The discussion must be visible to the caller, including groups. The subject defaults to Re: plus the parent subject. The reply is queued for the normal forum email.

        Parameter Type Required Default Description
        postId integer yes — Post id to reply to.
        message string yes — Reply message as HTML.
        subject string no — Optional subject. Omit it to use Re: and the parent subject. (max. 255)

        Returns: discussionId, postId, parentId, forumId, cmid, url.

        Scope: write. Moodle permissions: mod/forum:replynews in the announcements forum, mod/forum:replypost elsewhere.

        Example arguments:

        {"postId": 5521, "message": "<p>Thanks, fixed.</p>"}
        

        send_private_message

        Send a private Moodle message to a user id. The text is HTML and is cleaned before it is stored. The recipient's messaging preference (anyone, course members or contacts only) and any block are honoured. Reuses the existing individual conversation when there is one.

        Parameter Type Required Default Description
        userId integer yes — Recipient user id.
        message string yes — Message as HTML.

        Returns: conversationId, messageId, userId, text.

        Scope: write. Moodle permissions: moodle/site:sendmessage.

        Example arguments:

        {"userId": 205, "message": "<p>Your resubmission is due on Friday.</p>"}
        

        reply_conversation

        Send a message into a Moodle conversation the current user is a member of. The text is HTML and is cleaned before it is stored. A private conversation also honours the other person's messaging preference.

        Parameter Type Required Default Description
        conversationId integer yes — Conversation id from list_conversations or send_private_message.
        message string yes — Message as HTML.

        Returns: conversationId, messageId, text.

        Scope: write. Moodle permissions: moodle/site:sendmessage and membership of the conversation.

        Example arguments:

        {"conversationId": 17, "message": "<p>See you on Monday.</p>"}
        

        User accounts (admin scope)

        create_user

        Create a site account. Auth defaults to manual. If password is omitted, Moodle generates one and emails it. The password is never included in the response. dryRun true checks the account and saves nothing. Requires the admin scope, write tools, and moodle/user:create.

        Parameter Type Required Default Description
        username string yes — Login name. Stored in lowercase. (max. 100)
        firstname string yes — First name. (max. 100)
        lastname string yes — Last name. (max. 100)
        email string yes — Email address. Must be unique unless the site allows duplicates. (max. 100)
        auth string no "manual" Enabled authentication plugin.
        password string no — Optional password. If omitted, Moodle generates one and emails the user. Never returned. (max. 255)
        idnumber string no — Optional institution id. (max. 255)
        dryRun boolean no false When true, validate the account and do not create it or send email.

        Returns: dryRun, userId, username, passwordGenerated, passwordSent.

        Scope: admin. Moodle permissions: Scope admin, write tools enabled and moodle/user:create (system).

        Example arguments:

        {"username": "ada", "firstname": "Ada", "lastname": "Lovelace", "email": "[email protected]", "dryRun": true}
        

        create_users

        Create up to 20 accounts. If any row is invalid, none are created. Passwords are never returned. dryRun true validates the list only. Requires the admin scope, write tools, and moodle/user:create.

        Parameter Type Required Default Description
        users array yes — Accounts to create. (up to 20)
        dryRun boolean no false When true, validate every row and create nothing.

        Fields of each item in users:

        • username* (string): Login name. Stored in lowercase. (max. 100)
        • firstname* (string): First name. (max. 100)
        • lastname* (string): Last name. (max. 100)
        • email* (string): Email address. Must be unique unless the site allows duplicates. (max. 100)
        • auth (string): Enabled authentication plugin.
        • password (string): Optional password. If omitted, Moodle generates one and emails the user. Never returned. (max. 255)
        • idnumber (string): Optional institution id. (max. 255)

        * = required.

        Returns: dryRun, users[].

        Scope: admin. Moodle permissions: Scope admin, write tools enabled and moodle/user:create (system).

        Example arguments:

        {"users": [{"username": "ada", "firstname": "Ada", "lastname": "Lovelace", "email": "[email protected]"}], "dryRun": true}
        

        update_user

        Update first name, last name, email, idnumber, city, country, institution or department. Identify the account with userId, username or email. dryRun true changes nothing. Requires the admin scope, write tools, and moodle/user:update. Accounts are not deleted here.

        Parameter Type Required Default Description
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — New email. Omit it to leave the current value. (max. 255)
        firstname string no — New firstname. Omit it to leave the current value. (max. 255)
        lastname string no — New lastname. Omit it to leave the current value. (max. 255)
        idnumber string no — New idnumber. Omit it to leave the current value. (max. 255)
        city string no — New city. Omit it to leave the current value. (max. 255)
        country string no — New country. Omit it to leave the current value. (max. 255)
        institution string no — New institution. Omit it to leave the current value. (max. 255)
        department string no — New department. Omit it to leave the current value. (max. 255)
        auth string no — Enabled authentication plugin.
        dryRun boolean no false When true, check the change and do not save it.

        Returns: dryRun, userId, updated[].

        Scope: admin. Moodle permissions: Scope admin, write tools enabled and moodle/user:update (system).

        Example arguments:

        {"username": "ada", "department": "Mathematics"}
        

        suspend_user

        Suspend an account so the person cannot log in. The account is not deleted. You cannot suspend yourself, the guest, or a site administrator. dryRun true changes nothing. Requires the admin scope, write tools, and moodle/user:update.

        Parameter Type Required Default Description
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        dryRun boolean no false When true, check the account and do not suspend it.

        Returns: userId, suspended, dryRun.

        Scope: admin. Moodle permissions: Scope admin, write tools enabled and moodle/user:update (system).

        Example arguments:

        {"username": "ada", "dryRun": true}
        

        unsuspend_user

        Remove the suspension from an account. dryRun true changes nothing. Requires the admin scope, write tools, and moodle/user:update.

        Parameter Type Required Default Description
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        dryRun boolean no false When true, check the account and do not unsuspend it.

        Returns: userId, suspended, dryRun.

        Scope: admin. Moodle permissions: Scope admin, write tools enabled and moodle/user:update (system).

        Example arguments:

        {"username": "ada"}
        

        Site policies (admin scope)

        set_site_policy_handler

        Set sitepolicyhandler to tool_policy, or clear it. enabled: true activates the Policies plugin. enabled: false clears it when it is tool_policy and refuses to clear a different handler.

        Parameter Type Required Default Description
        enabled boolean yes — True sets sitepolicyhandler to tool_policy. False clears that handler.

        Returns: enabled, handler.

        Scope: admin. Moodle permissions: moodle/site:config.

        Example arguments:

        {"enabled": true}
        

        create_policy

        Create a site policy and its first version with tool_policy\api::form_policydoc_add. name, summary and content are required. type defaults to site, audience to all, and optional to false (compulsory). activate: true makes the version current; otherwise it stays a draft.

        Parameter Type Required Default Description
        name string yes — Policy name. (max. 1333)
        type string no — Omitted on create means site. Values: site, privacy, thirdparty, other.
        audience string no — Omitted on create means all. Values: all, loggedin, guests.
        optional boolean no — True when users may decline. False, the default on create, means the policy is compulsory.
        revision string no — Revision label. An empty value lets Moodle use the creation date. (max. 1333)
        summary string yes — Summary HTML. Cleaned before it is stored.
        content string yes — Full policy HTML. Cleaned before it is stored.
        activate boolean no — True makes this version the current one. False, the default, saves a draft.

        Returns: policyId, versionId, currentVersionId, name, type, audience, optional, revision, summary, content, status.

        Scope: admin. Moodle permissions: tool/policy:managedocs.

        Example arguments:

        {"name": "Terms of use", "summary": "<p>Short version.</p>", "content": "<p>Full text.</p>", "activate": true}
        

        update_policy

        Update a site policy with tool_policy\api. versionId defaults to the current version, or the newest draft when nothing is current. minorChange: true overwrites that version (not an archived one); otherwise a new version is saved. activate: true makes it current. inactivate: true archives the current version. Send activate or inactivate, not both.

        Parameter Type Required Default Description
        policyId integer yes — Policy document id.
        versionId integer no — Version to edit. Omitted uses the current version, or the newest draft.
        minorChange boolean no — True overwrites the version. False, the default, saves a new version.
        activate boolean no — True makes the saved version current.
        inactivate boolean no — True archives the current version and leaves the policy with no current version.
        name string no — Policy name. (max. 1333)
        type string no — Omitted on create means site. Values: site, privacy, thirdparty, other.
        audience string no — Omitted on create means all. Values: all, loggedin, guests.
        optional boolean no — True when users may decline. False, the default on create, means the policy is compulsory.
        revision string no — Revision label. An empty value lets Moodle use the creation date. (max. 1333)
        summary string no — Summary HTML. Cleaned before it is stored.
        content string no — Full policy HTML. Cleaned before it is stored.

        Returns: policyId, versionId, currentVersionId, name, type, audience, optional, revision, summary, content, status.

        Scope: admin. Moodle permissions: tool/policy:managedocs.

        Example arguments:

        {"policyId": 3, "content": "<p>Updated text.</p>", "activate": true}
        

        list_policies

        List site policies and their versions. Each version status is draft, active or archived. policyId limits the list to one policy. It does not change anything, but like the other admin tools it needs write tools switched on.

        Parameter Type Required Default Description
        policyId integer no — When set, return only this policy.

        Returns: policies[].

        Scope: admin. Moodle permissions: tool/policy:managedocs.

        Example arguments:

        {}
        

        get_policy_acceptances

        List who has accepted, declined or not yet answered one policy version. Filter by course and by one user. accepted, declined and pending count everyone who matches; acceptances is capped by limit. A guest-only policy has no user acceptances. It does not change anything, but like the other admin tools it needs write tools switched on.

        Parameter Type Required Default Description
        versionId integer yes — Policy version id.
        courseId integer no — Only users enrolled in this course. Alternative to courseShortname.
        courseShortname string no — Exact course short name. Alternative to courseId. (max. 255)
        limit integer no 100 Maximum users to return. The counts still include everyone who matches. (1–500)
        userId integer no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email.
        username string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)
        email string no — One of three alternative ways to identify the same user. Fill in only one of userId, username or email. (max. 100)

        Returns: policyId, versionId, name, revision, accepted, declined, pending, truncated, acceptances[].

        Scope: admin. Moodle permissions: tool/policy:viewacceptances.

        Example arguments:

        {"versionId": 7, "courseId": 42}