Contents
On this page

Create Subject - Plugixa Exam

POST /plugixa-exam/v1/subjects

Create a subject, at the top level or under another subject.

Scope subjects:write; the token’s user needs the subjects:create permission.

Request

POST https://your-site.example/wp-json/plugixa-exam/v1/subjects

Request body

Content type: application/json

Field Type Required Description
title string Yes Must not be blank.
slug string No Made from the title when empty. Made unique by appending -2, -3, …
code string No Your own reference. Must be unique among live subjects.
description string No HTML. Tags outside the question-text allow-list are stripped.
parent_id integer No 0 for the top level (the default). Must be an existing subject. Subjects nest at most 10 levels deep.
published boolean No Defaults to false: a subject created without it is unpublished.

The new subject is placed last under its parent. level, path and ordering are worked out for you; values sent for them are ignored.

{
  "title": "Algebra",
  "parent_id": 3,
  "code": "MATH-ALG",
  "published": true
}

Responses

201 Created. data is the new subject.

{
  "success": true,
  "data": {
    "id": 12,
    "parent_id": 3,
    "path": "3/12",
    "level": 2,
    "code": "MATH-ALG",
    "title": "Algebra",
    "slug": "algebra",
    "description": "",
    "ordering": 4,
    "published": true,
    "created_at": "2026-11-12 09:30:00",
    "modified_at": "2026-11-12 09:30:00",
    "created_by": 1,
    "modified_by": 1,
    "deleted_at": null
  }
}
Field Type Meaning
data.id integer The new subject’s id
data.parent_id integer 0 at the top level
data.path string The ids from the top level down to this subject
data.level integer Depth, from 1
data.code string|null Your reference, or null
data.ordering integer Position among its siblings
data.published boolean Whether the subject is published
data.created_at string UTC datetime
data.deleted_at string|null null unless the subject is in the trash

Errors

Status Code When
400 plugixa_exam_title_required title is missing or blank.
400 plugixa_exam_invalid_parent parent_id is not an existing subject.
400 plugixa_exam_too_deep The subject would sit more than 10 levels deep.
409 plugixa_exam_code_taken Another subject already uses code.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-exam/v1/subjects" \
  -H "Authorization: Bearer $PLUGIXA_EXAM_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title":"Algebra","parent_id":3,"code":"MATH-ALG","published":true}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-exam/v1/subjects');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer ' . getenv('PLUGIXA_EXAM_TOKEN'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS     => json_encode([
        'title'     => 'Algebra',
        'parent_id' => 3,
        'code'      => 'MATH-ALG',
        'published' => true,
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-exam/v1/subjects', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.PLUGIXA_EXAM_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ title: 'Algebra', parent_id: 3, code: 'MATH-ALG', published: true }),
});
const { data } = await response.json();

Quick Links

Share