Contents
On this page

List Cohorts for Access Rules - Plugixa Exam

GET /plugixa-exam/v1/cohorts/picker

List the published cohorts by id and name, to build a cohort 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:edit permission: it is a helper for editing exam access. When it refuses, the code is WordPress’s own rest_forbidden.

Request

GET https://your-site.example/wp-json/plugixa-exam/v1/cohorts/picker

Responses

200 OK. data is the list of published cohorts.

Sorted by name, at most 500. Not paged.

{
  "success": true,
  "data": [
    { "id": 4, "title": "Grade 10 - Section A" },
    { "id": 6, "title": "Grade 10 - Section B" }
  ]
}
Field Type Meaning
data[].id integer The cohort’s id, for subject_id in a rule
data[].title string The cohort’s name

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/picker" \
  -u "$WP_USER:$WP_APP_PASSWORD"
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-exam/v1/cohorts/picker');
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/picker', {
  headers: {
    'Authorization': 'Basic ' + btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`),
  },
});
const { data } = await response.json();

Quick Links

Share