Contents
List Roles and Capabilities for Access Rules - Plugixa Exam
GET /plugixa-exam/v1/cohorts/subjects
List the site’s WordPress roles and every capability those roles grant, to build a role or level access rule.
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. This read needs the
exams:editpermission, and it lists every role and capability on the site, not only Plugixa Exam’s. When it refuses, the code is WordPress’s ownrest_forbidden.
Request
GET https://your-site.example/wp-json/plugixa-exam/v1/cohorts/subjects
Responses
200 OK. data holds the roles and the capabilities.
{
"success": true,
"data": {
"roles": [
{ "slug": "administrator", "name": "Administrator" },
{ "slug": "editor", "name": "Editor" },
{ "slug": "subscriber", "name": "Subscriber" }
],
"capabilities": [
"edit_posts",
"manage_options",
"publish_posts",
"read"
]
}
}
| Field | Type | Meaning |
|---|---|---|
data.roles[].slug |
string |
The role, for subject_slug in a role rule |
data.roles[].name |
string |
The role’s name, in the site’s language |
data.capabilities |
string[] |
Every capability granted by at least one role, sorted, for subject_slug in a level rule |
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 "https://your-site.example/wp-json/plugixa-exam/v1/cohorts/subjects" \
-u "$WP_USER:$WP_APP_PASSWORD"
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-exam/v1/cohorts/subjects');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Basic ' . base64_encode(getenv('WP_USER') . ':' . getenv('WP_APP_PASSWORD')),
],
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-exam/v1/cohorts/subjects', {
headers: {
'Authorization': 'Basic ' + btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`),
},
});
const { data } = await response.json();
Quick Links
Share