Contents
On this page
Compare Question Versions - Plugixa Exam
GET /plugixa-exam/v1/questions/{id}/compare
Compare two saved versions of a question: each text field before and after, and the options lined up by position.
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 questions:view permission. It needs Plugixa Exam Pro with the Version history app on in Plugixa Exam -> App Manager: with the app off, the route answers 404.
Request
GET https://your-site.example/wp-json/plugixa-exam/v1/questions/12/compare?from=1&to=2
Path parameters
| Name | Type | Description |
|---|---|---|
id |
integer |
The question’s id |
Query parameters
| Name | Type | Default | Description |
|---|---|---|---|
from |
integer |
The older version number. | |
to |
integer |
The newer version number. |
Both are needed in practice: if either is missing, or names a version the question does not have, the answer is 404.
Responses
200 OK. data is the comparison.
{
"success": true,
"data": {
"from": 1,
"to": 2,
"fields": [
{
"field": "title",
"kind": "text",
"changed": true,
"before": "Capital city of France",
"after": "Capital of France"
},
{
"field": "stem",
"kind": "html",
"changed": false,
"before": "<p>What is the capital of France?</p>",
"after": "<p>What is the capital of France?</p>"
},
{
"field": "explanation",
"kind": "html",
"changed": true,
"before": "",
"after": "<p>Paris is the capital of France.</p>"
},
{
"field": "answer_key",
"kind": "structure",
"changed": false,
"before": "{\n \"negative_marking\": false,\n \"min_score\": 0\n}",
"after": "{\n \"negative_marking\": false,\n \"min_score\": 0\n}"
},
{
"field": "rubric",
"kind": "structure",
"changed": false,
"before": "",
"after": ""
}
],
"options": [
{ "position": 1, "before": "Paris", "after": "Paris", "before_correct": true, "after_correct": true, "changed": false },
{ "position": 2, "before": "Lyon", "after": "Lyon", "before_correct": false, "after_correct": false, "changed": false },
{ "position": 3, "before": null, "after": "Marseille", "before_correct": null, "after_correct": false, "changed": true }
]
}
}
| Field | Type | Meaning |
|---|---|---|
data.from |
integer |
The older version number |
data.to |
integer |
The newer version number |
data.fields[].field |
string |
title, stem, explanation, answer_key or rubric |
data.fields[].kind |
string |
text, html, or structure for the answer key and rubric |
data.fields[].changed |
boolean |
Whether the field differs between the two versions |
data.fields[].before |
string |
The value in from. A structure field is given as pretty-printed JSON text. An empty value is "" |
data.fields[].after |
string |
The value in to, the same way |
data.options[].position |
integer |
Position in the list, from 1 |
data.options[].before |
string|null |
Option text in from, or null when that version had no option at this position |
data.options[].after |
string|null |
Option text in to, or null |
data.options[].before_correct |
boolean|null |
Whether the option was correct in from |
data.options[].after_correct |
boolean|null |
Whether it is correct in to |
data.options[].changed |
boolean |
Whether this position differs |
Options are compared by position, up to the longer of the two lists, so an added option shows as null before, and reordering shows as several changed positions rather than a move.
Errors
| Status | Code | When |
|---|---|---|
404 |
plugixa_exam_not_found |
Either version does not exist for that question, including when from or to is missing. |
Plus the errors every endpoint can return.
Examples
curl -s "https://your-site.example/wp-json/plugixa-exam/v1/questions/12/compare?from=1&to=2" \
-u "$WP_USER:$WP_APP_PASSWORD"
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-exam/v1/questions/12/compare?from=1&to=2');
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/questions/12/compare?from=1&to=2', {
headers: {
'Authorization': 'Basic ' + btoa(`${process.env.WP_USER}:${process.env.WP_APP_PASSWORD}`),
},
});
const { data } = await response.json();
Quick Links
Share