Update Subject
PATCH /v1/nextexams/subjects/{id}
Update a subject
Changes only the fields you send. Moving a subject (parent_id) rebuilds
the path of its whole subtree; a move under its own descendant is refused.
Scope subjects:write; the role needs subjects.edit.
Request
PATCH https://your-site.example/api/index.php/v1/nextexams/subjects/{id}
Parameters
| Name | Type | In | Required | Description |
|---|---|---|---|---|
id |
integer |
path |
Yes | The record's id. (min 1) |
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
title |
string |
No | Required on create. |
parent_id |
integer |
No | 0 for the top level. |
code |
string |
No | |
alias |
string |
No | Made from the title when empty. |
description |
string |
No | |
published |
integer |
No | One of 0, 1. |
{
"title": "Linear algebra"
}
Responses
200 — Saved.
{
"data": {
"id": 1
}
}
| Field | Type | Meaning |
|---|---|---|
data.id |
integer |
Errors
| Status | Code | When |
|---|---|---|
400 |
BAD_REQUEST |
The body failed validation, or is not a JSON object (INVALID_JSON). |
401 |
INVALID_TOKEN |
No token (MISSING_TOKEN), or one that is wrong, expired, revoked, or whose owner can no longer sign in (INVALID_TOKEN). |
403 |
MISSING_SCOPE |
The token is valid but this request is not allowed, and code says why: MISSING_SCOPE (the token lacks the scope), FORBIDDEN (the owner's role does not allow it), ACCESS_DENIED (the owner cannot manage Next Exams), API_DISABLED (the API Tokens app is off), APP_DISABLED (the feature's app is off — meta.app names it), ACCOUNT_UNUSABLE (the owner is blocked or must reset their password), DEMO_LOCKED (a demo site). |
404 |
NOT_FOUND |
No record has this id. |
Examples
curl
curl -s -X PATCH "https://your-site.example/api/index.php/v1/nextexams/subjects/1" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"title":"Linear algebra"}'
PHP
<?php
$ch = curl_init('https://your-site.example/api/index.php/v1/nextexams/subjects/1');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('API_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => '{"title":"Linear algebra"}',
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
JavaScript
const API_TOKEN = process.env.API_TOKEN;
const response = await fetch("https://your-site.example/api/index.php/v1/nextexams/subjects/1", {
method: 'PATCH',
headers: {
"Authorization": `Bearer ${API_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"title": "Linear algebra"
}),
});
const data = await response.json();