Skip to content

RAG chunks DataTables feed

GET
/wp-json/wp2tutor/rag/v1/datatables
curl --request GET \
--url 'https://example.com/wp-json/wp2tutor/rag/v1/datatables?draw=1&start=0&length=25&search%5Bvalue%5D=embedding&order%5B0%5D%5Bcolumn%5D=6&order%5B0%5D%5Bdir%5D=desc' \
--header 'X-WP-Nonce: <X-WP-Nonce>'

Server-side SQLite chunks for the current blog in DataTables shape. PHP ChunksDataTablesController::datatables: array_merge(get_query_params(), get_body_params()) — JSON body is not read. Admin UI (chunks_datatable.js) sends GET with X-WP-Nonce, pageLength 25, order [[6, desc]] (created_at column). Search is LIKE on content, id_post, id_chunk, content_hash, metadata. No PDO → recordsTotal/recordsFiltered 0, data []. Requires manage_options. Not the chat runtime.

draw
integer
default: 1 >= 1

DataTables draw counter. PHP (int) then max(1, …); default 1. Echoed as response draw.

Example
1
start
integer
0

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

Example
0
length
integer
default: 25 >= 1 <= 100

LIMIT. PHP min(100, max(1, (int))), default 25. Admin lengthMenu is 25/50/75/100.

Example
25
search[value]
string

DataTables search string. PHP: $params['search']['value'], sanitize_text_field. LIKE %term% on content, id_post, id_chunk, content_hash, metadata. Empty — no filter.

Example
embedding
order[0][column]
integer
default: 3

DataTables column index (order[0][column]). PHP (int), default 3. ChunkReadModel: 1 → status, 2 → id_chunk, 5 → id_post, 6 → created_at; anything else (including 3 preview, 4 metadata) → created_at. Admin default column is 6.

Example
6
order[0][dir]
string
default: desc
Allowed values: asc desc ASC DESC

Direction (order[0][dir]). PHP sanitize_key, then ASC only if the string is ASC (case-insensitive), otherwise DESC. Default desc.

Example
desc

DataTables { draw, recordsTotal, recordsFiltered, data }. draw is echoed (min 1). recordsTotal is COUNT for id_site. recordsFiltered is COUNT after search.

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
}
}