Contents
On this page
Replace Exam Access Rules - Plugixa Exam
PUT /plugixa-exam/v1/exams/{id}/access
Replace every access rule of an exam with the list you send.
Not reachable with an API token: since 1.4.1 a token request to this route answers 403 plugixa_exam_token_route. Call it as a signed-in WordPress user (from a script, with an Application Password) who holds the exams:edit permission. Needs Plugixa Exam Pro with the Cohorts app on in Plugixa Exam -> App Manager; with it off, this route answers 404.
Note. All existing rules are deleted first, then the valid rows you send are saved. A row that is not valid is dropped without an error, so compare the response with what you sent. When the request is refused, the code is WordPress’s own
rest_forbidden.
The rules only decide who may sit the exam when its access_type is restricted (see Create Exam). To find the ids and slugs to put in a rule, use List Cohorts for Access Rules, List Roles and Capabilities for Access Rules and Search Users for Access Rules.
Request
PUT https://your-site.example/wp-json/plugixa-exam/v1/exams/7/access
Path parameters
| Name | Type | Description |
|---|---|---|
id |
integer |
The exam’s id. Not checked for existence |
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
rules |
object[] |
No | The rules. Missing or empty removes them all. |
rules[].subject_type |
string |
Yes | cohort, role, user or level (a capability). Any other value drops the row. |
rules[].subject_id |
integer |
For cohort and user |
The cohort or user id. A cohort or user row without it is dropped. |
rules[].subject_slug |
string |
For role and level |
The role slug or capability name. A role or level row without it is dropped. |
rules[].available_from |
string |
No | When the rule starts letting people in, as a date and time. Stored in UTC. |
rules[].available_until |
string |
No | When the rule stops letting people in. |
rules[].due_at |
string |
No | A deadline. |
A date that cannot be read is stored as no date.
{
"rules": [
{
"subject_type": "cohort",
"subject_id": 4,
"available_from": "2026-11-16 08:00:00",
"available_until": "2026-11-18 18:00:00",
"due_at": "2026-11-18 18:00:00"
},
{ "subject_type": "user", "subject_id": 58 }
]
}
Responses
200 OK. data is the saved list of rules.
The same shape as Get Exam Access Rules, without meta. The rules get new ids on every save.
{
"success": true,
"data": [
{
"id": 33,
"exam_id": 7,
"subject_type": "cohort",
"subject_id": 4,
"subject_slug": "",
"available_from": "2026-11-16 08:00:00",
"available_until": "2026-11-18 18:00:00",
"due_at": "2026-11-18 18:00:00",
"created_at": "2026-11-12 10:40:00",
"modified_at": "2026-11-12 10:40:00",
"created_by": 1,
"modified_by": 1
},
{
"id": 34,
"exam_id": 7,
"subject_type": "user",
"subject_id": 58,
"subject_slug": "",
"available_from": null,
"available_until": null,
"due_at": null,
"created_at": "2026-11-12 10:40:00",
"modified_at": "2026-11-12 10:40:00",
"created_by": 1,
"modified_by": 1
}
]
}
| Field | Type | Meaning |
|---|---|---|
data[].id |
integer |
The rule’s new id |
data[].subject_type |
string |
cohort, role, user or level |
data[].subject_id |
integer |
The cohort or user id, 0 for role and level |
data[].subject_slug |
string |
The role or capability, "" for cohort and user |
data[].available_from |
string|null |
UTC datetime, null for no start |
data[].available_until |
string|null |
UTC datetime, null for no end |
data[].due_at |
string|null |
UTC deadline, null for none |
Errors
| Status | Code | When |
|---|---|---|
401 / 403 |
rest_forbidden |
Not signed in (401), or the user may not edit exams (403). |
Plus the errors every endpoint can return.
Examples
curl -s -X PUT "https://your-site.example/wp-json/plugixa-exam/v1/exams/7/access" \
-u "$WP_USER:$WP_APP_PASSWORD" \
-H "Content-Type: application/json" \
-d '{"rules":[{"subject_type":"cohort","subject_id":4,"available_from":"2026-11-16 08:00:00","available_until":"2026-11-18 18:00:00","due_at":"2026-11-18 18:00:00"},{"subject_type":"user","subject_id":58}]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-exam/v1/exams/7/access');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Basic ' . base64_encode(getenv('WP_USER') . ':' . getenv('WP_APP_PASSWORD')),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'rules' => [
[
'subject_type' => 'cohort',
'subject_id' => 4,
'available_from' => '2026-11-16 08:00:00',
'available_until' => '2026-11-18 18:00:00',
'due_at' => '2026-11-18 18:00:00',
],
['subject_type' => 'user', 'subject_id' => 58],
],
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-exam/v1/exams/7/access', {
method: 'PUT',
headers: {
'Authorization': 'Basic ' + btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`),
'Content-Type': 'application/json',
},
body: JSON.stringify({
rules: [
{
subject_type: 'cohort',
subject_id: 4,
available_from: '2026-11-16 08:00:00',
available_until: '2026-11-18 18:00:00',
due_at: '2026-11-18 18:00:00',
},
{ subject_type: 'user', subject_id: 58 },
],
}),
});
const { data } = await response.json();
Quick Links
Share