Skip to content

Web services

The Programs plugin exposes a set of Moodle web services for integration with external systems. All services require the caller to be authenticated and to hold the appropriate capability in the program’s context.

Returns a list of programs matching the given search parameters.

Capability: tool/muprog:view

Parameters:

NameTypeDescription
fieldvaluesarrayList of field/value pairs to filter by. Accepted fields: id, contextid, fullname, idnumber, publicaccess, archived, tenantid.

Returns: Array of program objects including id, fullname, idnumber, description, visibility settings, allocation date windows, start/due/end date logic, and lists of enabled allocation sources and visible cohort ids.


Returns a list of allocations for a given program, optionally filtered by user.

Capability: tool/muprog:view

Parameters:

NameTypeDescription
programidintProgram id.
useridsint[]Optional list of user ids. Empty or null means all allocated users.

Returns: Array of allocation objects. See tool_muprog_update_program_allocation for the allocation object structure.


Manually allocates users or cohort members to a program.

Capability: tool/muprog:allocate, moodle/cohort:view

Parameters:

NameTypeDescription
programidintProgram id.
useridsint[]Optional list of user ids to allocate.
cohortidsint[]Optional list of cohort ids whose members will be allocated.
dateoverridesobjectOptional date overrides: timestart, timedue, timeend as Unix timestamps.

Returns: Array of user ids that were allocated (already allocated users are skipped).


Deallocates users from a program.

Capability: tool/muprog:deallocate

Parameters:

NameTypeDescription
programidintProgram id.
useridsint[]List of user ids to deallocate.

Returns: Array of user ids that were deallocated.


Updates allocation dates for a user in a program.

Capability: tool/muprog:admin

Parameters:

NameTypeDescription
programidintProgram id.
useridintUser id.
allocationdatesobjectOptional date updates: timestart, timedue, timeend as Unix timestamps.

Returns: Allocation object with the following fields:

FieldTypeDescription
idintAllocation id.
programidintProgram id.
useridintUser id.
sourceidintAllocation source id.
sourcetypestringInternal source name (e.g. manual, cohort).
archivedboolWhether the allocation is archived.
timeallocatedintDate allocated.
timestartintStart date.
timedueintDue date.
timeendintEnd date.
timecompletedintCompletion date.
timecreatedintRecord creation date.
deletepossibleboolWhether deallocation is possible.
archivepossibleboolWhether archiving is possible.
restorepossibleboolWhether restoring is possible.
editpossibleboolWhether editing is possible.

Archives a user’s allocation in a program.

Capability: tool/muprog:deallocate

Parameters:

NameTypeDescription
programidintProgram id.
useridintUser id.

Returns: Updated allocation object (same structure as tool_muprog_update_program_allocation).


Restores an archived allocation.

Capability: tool/muprog:allocate

Parameters:

NameTypeDescription
programidintProgram id.
useridintUser id.

Returns: Updated allocation object (same structure as tool_muprog_update_program_allocation).


Returns the list of cohorts synchronised with a program’s cohort allocation source.

Capability: tool/muprog:view

Parameters:

NameTypeDescription
programidintProgram id.

Returns: Array of cohort objects: id, contextid, name, idnumber.


Adds a cohort to the program’s cohort allocation source.

Capability: tool/muprog:edit, moodle/cohort:view

Parameters:

NameTypeDescription
programidintProgram id.
cohortidintCohort id to add.

Returns: Updated list of synchronised cohorts (same structure as tool_muprog_source_cohort_get_cohorts).


Removes a cohort from the program’s cohort allocation source.

Capability: tool/muprog:edit

Parameters:

NameTypeDescription
programidintProgram id.
cohortidintCohort id to remove.

Returns: Updated list of synchronised cohorts (same structure as tool_muprog_source_cohort_get_cohorts).