Skip to content

RAG chunks DataTables feed (POST)

POST
/wp-json/wp2tutor/rag/v1/datatables
curl --request POST \
--url https://example.com/wp-json/wp2tutor/rag/v1/datatables \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'X-WP-Nonce: <X-WP-Nonce>' \
--data draw=1 \
--data start=0 \
--data length=25 \
--data-urlencode search%5Bvalue%5D=embedding \
--data-urlencode order%5B0%5D%5Bcolumn%5D=6 \
--data-urlencode order%5B0%5D%5Bdir%5D=desc

Same datatables() as GET. Parameters come from query and get_body_params() (form-urlencoded nested DataTables keys: search[value], order[0][column], order[0][dir]). get_json_params() is unused — PHP does not read a JSON body. Admin UI sends GET; POST is for clients that POST the DataTables protocol. Same response. Requires manage_options.

Media typeapplication/x-www-form-urlencoded
object
draw

DataTables draw counter. PHP max(1, (int)), default 1. Echoed in the response.

integer
start

OFFSET. PHP max(0, (int)), default 0.

integer
length

LIMIT. PHP min(100, max(1, (int))), default 25.

integer
search[value]

Search. In PHP this becomes $params[‘search’][‘value’].

string
order[0][column]

Column index. In PHP $params[‘order’][0][‘column’]. 1 status, 2 id_chunk, 5 id_post, 6 created_at.

integer
order[0][dir]

Asc/desc. In PHP $params[‘order’][0][‘dir’]; not ASC → DESC.

string
Example
draw=1&start=0&length=25&search%5Bvalue%5D=embedding&order%5B0%5D%5Bcolumn%5D=6&order%5B0%5D%5Bdir%5D=desc

Same DataTables object as GET.

Media typeapplication/json
object
draw

Echo of input draw after max(1, …).

integer
recordsTotal

COUNT(*) of chunks for the current id_site with no search. No PDO → 0.

integer
recordsFiltered

COUNT(*) after LIKE search (equals recordsTotal when search is empty). No PDO → 0.

integer
data

Page rows (LIMIT/OFFSET). Not a WP_Error/license payload.

Array<object>
object
select

PHP always ''. The checkbox is rendered by the DataTables client, not REST.

string
status

SQLite row ChunkStatus (0 PENDING, 1 ACTIVE, 2 INDEXING, −1 ERROR).

integer
status_icon

PHP match emoji: 1 → 🟢, 2 → 🔵, −1 → 🔴, else ⚪ (including PENDING 0).

string
id_chunk

Chunk id.

integer
content_preview

First sentence of content (up to .?! + space) or first 200 characters; HTML stripped, whitespace collapsed.

string
metadata_html

HTML from JSON metadata (source.post_type/anchor, taxonomies). Invalid JSON → ''.

string
source_post
object
id

Chunk id_post (WordPress post the fragment was cut from).

integer
title

Get_the_title(id_post); missing title → ''.

string
edit

Get_edit_post_link(id_post, raw); if not a string → ''.

string
created_at

UTC mysql datetime from SQLite (as current_time(‘mysql’, true)).

string
created_at_human

Local wp_date('d.m.Y H:i') after get_date_from_gmt.

string
Example
{
"draw": 1,
"recordsTotal": 120,
"recordsFiltered": 8,
"data": [
{
"select": "",
"status": 1,
"status_icon": "🟢",
"id_chunk": 42,
"content_preview": "Embedding is a vector representation of text.",
"metadata_html": "<div class=\"wp2tutor-rag-meta\"><h4>Source</h4><ul><li><strong>post_type:</strong> page</li></ul></div>",
"source_post": {
"id": 15,
"title": "Introduction to RAG",
"edit": "https://example.com/wp-admin/post.php?post=15&action=edit"
},
"created_at": "2026-09-13 10:00:00",
"created_at_human": "13.09.2026 13:00"
}
]
}

Not authenticated. DualRest: rest_forbidden (status 401) when there is no cookie session. Cookie + X-WP-Nonce or Application Password.

Media typeapplication/json
object
code

WP_Error code. For POST /chat 401 — rest_forbidden. DualRest cookie — rest_forbidden / rest_not_logged_in / rest_cookie_invalid_nonce.

string
message

WP_Error message (for the chat secret — Missing or invalid secret.).

string
data

Usually { status: HTTP code }, as PHP stores in WP_Error data.

object
Example
{
"code": "rest_forbidden",
"message": "Missing or invalid secret.",
"data": {
"status": 401
}
}

Missing manage_options or invalid REST nonce. WordPress REST: rest_forbidden / rest_cookie_invalid_nonce.

Media typeapplication/json
object
code

WP_Error code. For POST /chat 401 — rest_forbidden. DualRest cookie — rest_forbidden / rest_not_logged_in / rest_cookie_invalid_nonce.

string
message

WP_Error message (for the chat secret — Missing or invalid secret.).

string
data

Usually { status: HTTP code }, as PHP stores in WP_Error data.

object
Example
{
"code": "rest_forbidden",
"message": "Missing or invalid secret.",
"data": {
"status": 401
}
}