TABLE OF CONTENTS
- NexSIS API Introduction
- Requests
- Responses
- Health Checks
- Courses
- Users
- Enrolments
- Course Groups
- Grades
- Errors
NexSIS API Introduction
MoodleUS NexSIS API is a RESTful API that facilitates realtime integrations between Moodle and 3rd party systems, especially management information systems such as student information systems (SIS), human resources information systems (HRIS), and customer relationship management systems (CRM).
Why not Moodle core external services?
It is true that Moodle comes with external services available out of the box. These work well for their specific purpose; however, we have found that they are neither well geared towards nor designed for integration with a management information system. For example, they do not facilitate bulk operations, and they operate on the unique identifiers of the Moodle system.
MoodleUS has designed the NexSIS API from the ground up. Some of the key differences with Moodle's built-in external services are:
Simpler, more streamlined API calls geared towards a management information system
Facilitation of both individual and bulk operations
Operations performed on the unique identifiers of the external system
Requests
Authentication
Header authentication example:
GET /enrol/nexsis/api/index.php/ping HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Query parameter example:
GET /enrol/nexsis/api/index.php/ping?token={token} HTTP/1.1
Host: example.moodle.com
Accept: */*
NexSIS uses API keys to allow access to the API. You can enable the API and generate an API Key in the plugin's Moodle administration area.
NexSIS expects for the API key to be included in all API requests to the service. You have the option of passing the key in an Authorization header or as a query parameter named token.
The authorization header must follow the following format, where {token} is your API key:
Authorization: Bearer {token}
You must replace {token} with your API key.
HTTP Verbs
NexSIS API is a RESTful API and operates using the standard HTTP verbs. A brief description of each follows:
NexSIS considers the management information system to be the master record of some resources. Therefore, those resources do not support the POST verb. Since the resources already exist and have a unique identifier, and Moodle just has a copy of the resource, both Moodle creation and update use the PUT verb.
Sending Data
Example request (JSON):
PUT /enrol/nexsis/api/index.php/enpoint HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Content-Type: application/json
{
"param1": "value1",
"param2": "value2",
}
Example request (URL-encoded):
PUT /enrol/nexsis/api/index.php/enpoint HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Content-Type: application/x-www-form-urlencoded
param1=value1¶m2=value2
When sending data to the API, you can choose whether to send data in JSON or in URL-encoded format.
When sending JSON data, be sure to set the Content-Type header to application/json.
Responses
Unless otherwise noted or specified, all responses from the NexSIS API are JSON encoded format.
Health Checks
Ping
Endpoint:
GET /enrol/nexsis/api/index.php/ping
Example request:
GET /enrol/nexsis/api/index.php/ping HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"message": "pong"
}
This endpoint can be used to ping the API in order to determine its operational status.
Courses
Get a Course
Endpoint:
GET /enrol/nexsis/api/index.php/course/{courseid}
Example request:
GET /enrol/nexsis/api/index.php/course/C789 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"courseid": "C789",
"fullname": "Principles of API Design",
"shortname": "TECH-231"
"startdate": "2017-08-16T21:09:30+00:00",
"categorypath": "/Technology/Design/Modern Programming"
}
This endpoint retrieves a course.
URL Parameters:
Create/Update a Course
Endpoint:
PUT /enrol/nexsis/api/index.php/course/{courseid}
Example request (JSON):
PUT /enrol/nexsis/api/index.php/course/C789 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Content-Type: application/json
{
"fullname": "Principles of API Design",
"shortname": "TECH-231"
"startdate": "2017-08-16T21:09:30+00:00",
"categorypath": "/Technology/Design/Modern Programming"
}
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"courseid": "C789",
"fullname": "Principles of API Design",
"shortname": "TECH-231"
"startdate": "2017-08-16T21:09:30+00:00",
"categorypath": "/Technology/Design/Modern Programming"
}
This endpoint creates or updates a course.
URL Parameters
Body/JSON Parameters
Delete a Course
Endpoint:
DELETE /enrol/nexsis/api/index.php/course/{courseid}
Example request:
DELETE /enrol/nexsis/api/index.php/course/C789 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
This endpoint deletes a course.
URL Parameters
List Enrollments in a Course
Endpoint:
GET /enrol/nexsis/api/index.php/course/{courseid}/enrol
Example request:
GET /enrol/nexsis/api/index.php/course/C789/enrol HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"userenrol_id": "6",
"enrol": "manual",
"enrolstatus": "0",
"enrolstartdate": "0",
"enrolenddate": "0",
"firstname": "Test",
"lastname": "User",
"email": "[email protected]",
"idnumber": "U19913",
"role": "Student"
},
{
"userenrol_id": "4",
"enrol": "nexsis",
"enrolstatus": "0",
"enrolstartdate": "0",
"enrolenddate": "0",
"firstname": "Test2",
"lastname": "User",
"email": "[email protected]",
"idnumber": "U14845",
"role": "Student"
}
]
URL Parameters
Get Category Grades
Endpoint:
GET /enrol/nexsis/api/index.php/course/{courseid}/categorygrade/{catid}
Example request:
GET /enrol/nexsis/api/index.php/course/C789/categorygrade/6 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"user_idnumber": "u12345",
"itemid": "2",
"internal_userid": "5",
"rawgrade": null,
"rawgrademax": "100.00000",
"rawgrademin": "0.00000",
"rawscaleid": null,
"usermodified": null,
"finalgrade": "80.00000",
"hidden": "0",
"locked": "0",
"locktime": "0",
"exported": "0",
"overridden": "0",
"excluded": "0",
"feedback": null,
"feedbackformat": "0",
"information": null,
"informationformat": "0",
"timecreated": null,
"timemodified": "1590008438",
"aggregationstatus": "used",
"aggregationweight": "0.50000",
"gradeid": "6",
"categoryid": "2"
},
{
"user_idnumber": "u67890",
"itemid": "2",
"internal_userid": "4",
"rawgrade": null,
"rawgrademax": "100.00000",
"rawgrademin": "0.00000",
"rawscaleid": null,
"usermodified": null,
"finalgrade": "40.00000",
"hidden": "0",
"locked": "0",
"locktime": "0",
"exported": "0",
"overridden": "0",
"excluded": "0",
"feedback": null,
"feedbackformat": "0",
"information": null,
"informationformat": "0",
"timecreated": null,
"timemodified": "1590518968",
"aggregationstatus": "used",
"aggregationweight": "0.50000",
"gradeid": "12",
"categoryid": "2"
}
]
URL Parameters
Optional GET Parameters
Example using GET parameter to filter by user IDs:
GET /enrol/nexsis/api/index.php/course/C789/categorygrades/3?userid[]=u12345&userid[]=u67890
Override Category Grades
Endpoint:
PUT /enrol/nexsis/api/index.php/course/{courseid}/categorygrade/{catid}/{userid}/{grade}
Example request:
GET /enrol/nexsis/api/index.php/course/C789/categorygrade/6/U12345/80 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user_idnumber": "eli",
"id": "8",
"itemid": "4",
"internal_userid": "5",
"rawgrade": null,
"rawgrademax": "100.00000",
"rawgrademin": "0.00000",
"rawscaleid": null,
"usermodified": null,
"finalgrade": "80.00000",
"hidden": "0",
"locked": "0",
"locktime": "1590520163",
"exported": "0",
"overridden": "1590520163",
"excluded": "0",
"feedback": null,
"feedbackformat": "0",
"information": null,
"informationformat": "0",
"timecreated": null,
"timemodified": "1590008571",
"aggregationstatus": "used",
"aggregationweight": "0.50000"
}
URL Parameters
Optional GET Parameters
Example using an optional GET parameter to lock the grade:
PUT /enrol/nexsis/api/index.php/course/C789/categorygrades/3/U12345/80?lock=true
Users
Get a User
Endpoint:
GET /enrol/nexsis/api/index.php/user/{userid}
Example request:
GET /enrol/nexsis/api/index.php/user/S123 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"userid": "S123",
"username": "student123",
"firstname": "Student",
"lastname": "Smith",
"email": "[email protected]"
}
This endpoint retrieves a user.
URL Parameters
Create/Update a User
Endpoint:
PUT /enrol/nexsis/api/index.php/user/{userid}
Example request (JSON):
PUT /enrol/nexsis/api/index.php/user/S123 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Content-Type: application/json
{
"username": "student123",
"firstname": "Student",
"lastname": "Smith",
"email": "[email protected]"
}
Example request (URL-encoded):
PUT /enrol/nexsis/api/index.php/user/S123 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Content-Type: application/x-www-form-urlencoded
username=student123&firstname=Student&lastname=Smith&email=studentsmith%40inst.edu
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"userid": "S123",
"username": "student123",
"firstname": "Student",
"lastname": "Smith",
"email": "[email protected]"
}
This endpoint creates or updates a user.
URL Parameters
Body/JSON Parameters
Delete a User
Endpoint:
DELETE /enrol/nexsis/api/index.php/user/{userid}
Example request:
DELETE /enrol/nexsis/api/index.php/user/S123 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
This endpoint deletes a user.
URL Parameters
Enrolments
List User Enrolments
Endpoint:
GET /enrol/nexsis/api/index.php/user/{userid}/enrol
Example request:
GET /enrol/nexsis/api/index.php/user/S123/enrol HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"courseid": "C789",
"fullname": "Principles of API Design",
"shortname": "TECH-231"
"startdate": "2017-08-16T21:09:30+00:00",
"roles": [
"student"
]
},
{
"courseid": "C889",
"fullname": "Principles of API Design II",
"shortname": "TECH-331"
"startdate": "2017-08-16T21:09:30+00:00",
"roles": [
"student"
]
}
]
This endpoint retrieves all enrolments for a user.
URL Parameters
Optional GET Parameters
Example using GET parameter to list only NexSIS enrollments:
GET /enrol/nexsis/api/index.php/user/{userid}/enrol?plugin=nexsis
Enrol a User in a Course
Endpoint:
PUT /enrol/nexsis/api/index.php/user/{userid}/enrol/{courseid}
Example request:
POST /enrol/nexsis/api/index.php/user/S123/enrol/C789 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Content-Type: application/json
{
"roleid": "student"
}
This endpoint creates or updates a user enrolment in a course.
URL Parameters
Body/JSON Parameters
Unenrol a User from a Course
Endpoint:
DELETE /enrol/nexsis/api/index.php/user/{userid}/enrol/{courseid}
Example request:
DELETE /enrol/nexsis/api/index.php/user/S123/enrol/C789 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
This endpoint unenrols a user from a course.
URL Parameters
Optional GET Parameters
Example using optional GET parameter to delete only NexSIS enrolments:
DELETE /enrol/nexsis/api/index.php/user/{userid}/enrol/{courseid}?plugin=nexsis
Course Groups
List Course Groups
Endpoint:
GET /enrol/nexsis/api/index.php/course/{courseid}/group
Example request:
GET /enrol/nexsis/api/index.php/course/C789/group HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"groupid": "G1",
"name": "Group 1",
"description": "Group 1..."
},
{
"groupid": "G2",
"name": "Group 2",
"description": "Group 2..."
},
{
"groupid": "G3",
"name": "Group 3",
"description": "Group 3..."
}
]
This endpoint retrieves all groups for a given course.
URL Parameters
Get a Course Group
Endpoint:
GET /enrol/nexsis/api/index.php/course/{courseid}/group/{groupid}
Example request:
GET /enrol/nexsis/api/index.php/course/C789/group/G1 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"groupid": "G1",
"name": "Group 1",
"description": "Group 1..."
}
This endpoint retrieves a group for a given course.
URL Parameters
Create/Update a Course Group
Endpoint:
PUT /enrol/nexsis/api/index.php/course/{courseid}/group/{groupid}
Example request (JSON):
PUT /enrol/nexsis/api/index.php/course/C789/group/G1 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Content-Type: application/json
{
"name": "Group 1",
"description": "Group 1..."
}
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"groupid": "G1",
"name": "Group 1",
"description": "Group 1..."
}
This endpoint creates or updates a course group.
URL Parameters
Body/JSON Parameters
Delete a Course Group
Endpoint:
DELETE /enrol/nexsis/api/index.php/course/{courseid}/group/{groupid}
Example request:
DELETE /enrol/nexsis/api/index.php/course/C789/group/G1 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
This endpoint deletes a course group.
URL Parameters
Add/Update a Course Group User
Endpoint:
PUT /enrol/nexsis/api/index.php/course/{courseid}/group/{groupid}/user/{userid}
Example request (JSON):
PUT /enrol/nexsis/api/index.php/course/C789/group/G1/user/S123 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
This endpoint adds a user to a course group.
URL Parameters
Remove a Course Group User
Endpoint:
DELETE /enrol/nexsis/api/index.php/course/{courseid}/group/{groupid}/user/{userid}
Example request:
DELETE /enrol/nexsis/api/index.php/course/C789/group/G1/user/S123 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
This endpoint removes a user from a course group.
URL Parameters
Grades
The NexSIS API retrieves course level grades. These typically correspond to the course "final" grade.
Get User Grades
Endpoint:
GET /enrol/nexsis/api/index.php/user/{userid}/grade
Example request:
GET /enrol/nexsis/api/index.php/user/S123/grade HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"userid": "S123",
"courseid": "C789",
"rawfinalgrade": 92.00,
"rawgrademax": 100.00,
"gradeletter": "A-",
"gradepercent": 0.92,
"feedback": "Great effort!",
"timemodified": "2017-08-16T21:09:30+00:00"
},
{
"userid": "S123",
"courseid": "C799",
"rawfinalgrade": 950.00,
"rawgrademax": 1000.00,
"gradeletter": "A",
"gradepercent": 0.95,
"feedback": "Keep it up!",
"timemodified": "2017-08-15T18:12:21+00:00"
},
{
"userid": "S123",
"courseid": "C850",
"rawfinalgrade": 8.40,
"rawgrademax": 10.00,
"gradeletter": "B",
"gradepercent": 0.84,
"feedback": "",
"timemodified": "2017-10-02T09:43:54+00:00"
}
]
This endpoint retrieves a user's grades.
URL Parameters
Query String Parameters
Get Course Grades
Endpoint:
GET /enrol/nexsis/api/index.php/course/{courseid}/grade
Example request:
GET /enrol/nexsis/api/index.php/course/C789/grade?pagesize=3 HTTP/1.1
Authorization: Bearer {token}
Host: example.moodle.com
Accept: */*
Example response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
{
"userid": "S123",
"courseid": "C789",
"rawfinalgrade": 92.00,
"rawgrademax": 100.00,
"gradeletter": "A-",
"gradepercent": 0.92,
"feedback": "Great effort!",
"timemodified": "2017-08-16T21:09:30+00:00"
},
{
"userid": "S234",
"courseid": "C789",
"rawfinalgrade": 82.00,
"rawgrademax": 100.00,
"gradeletter": "B-",
"gradepercent": 0.82,
"feedback": "",
"timemodified": "2017-08-16T21:10:30+00:00"
},
{
"userid": "S345",
"courseid": "C789",
"rawfinalgrade": 96.00,
"rawgrademax": 100.00,
"gradeletter": "A",
"gradepercent": 0.96,
"feedback": "Great work!",
"timemodified": "2017-08-16T21:11:30+00:00"
}
]
This endpoint retrieves a course's grades.
URL Parameters
Query String Parameters
Errors
The NexSIS API uses the following error codes: