RAG chunks DataTables feed
const 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';const options = {method: 'GET', headers: {'X-WP-Nonce': '<X-WP-Nonce>'}};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Query Parameters
Section titled “Query Parameters”DataTables draw counter. PHP (int) then max(1, …); default 1. Echoed as response draw.
Example
1OFFSET. PHP max(0, (int)), default 0.
Example
0LIMIT. PHP min(100, max(1, (int))), default 25. Admin lengthMenu is 25/50/75/100.
Example
25DataTables search string. PHP: $params['search']['value'], sanitize_text_field. LIKE %term% on content, id_post, id_chunk, content_hash, metadata. Empty — no filter.
Example
embeddingDataTables 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
6Direction (order[0][dir]). PHP sanitize_key, then ASC only if the string is ASC (case-insensitive), otherwise DESC. Default desc.
Example
descResponses
Section titled “Responses”DataTables { draw, recordsTotal, recordsFiltered, data }. draw is echoed (min 1). recordsTotal is COUNT for id_site. recordsFiltered is COUNT after search.
object
Echo of input draw after max(1, …).
COUNT(*) of chunks for the current id_site with no search. No PDO → 0.
COUNT(*) after LIKE search (equals recordsTotal when search is empty). No PDO → 0.
Page rows (LIMIT/OFFSET). Not a WP_Error/license payload.
object
PHP always ''. The checkbox is rendered by the DataTables client, not REST.
SQLite row ChunkStatus (0 PENDING, 1 ACTIVE, 2 INDEXING, −1 ERROR).
PHP match emoji: 1 → 🟢, 2 → 🔵, −1 → 🔴, else ⚪ (including PENDING 0).
Chunk id.
First sentence of content (up to .?! + space) or first 200 characters; HTML stripped, whitespace collapsed.
HTML from JSON metadata (source.post_type/anchor, taxonomies). Invalid JSON → ''.
object
Chunk id_post (WordPress post the fragment was cut from).
Get_the_title(id_post); missing title → ''.
Get_edit_post_link(id_post, raw); if not a string → ''.
UTC mysql datetime from SQLite (as current_time(‘mysql’, true)).
Local wp_date('d.m.Y H:i') after get_date_from_gmt.
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.
object
WP_Error code. For POST /chat 401 — rest_forbidden. DualRest cookie — rest_forbidden / rest_not_logged_in / rest_cookie_invalid_nonce.
WP_Error message (for the chat secret — Missing or invalid secret.).
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.
object
WP_Error code. For POST /chat 401 — rest_forbidden. DualRest cookie — rest_forbidden / rest_not_logged_in / rest_cookie_invalid_nonce.
WP_Error message (for the chat secret — Missing or invalid secret.).
Usually { status: HTTP code }, as PHP stores in WP_Error data.
object
Example
{ "code": "rest_forbidden", "message": "Missing or invalid secret.", "data": { "status": 401 }}