RAG chunks DataTables feed (POST)
const url = 'https://example.com/wp-json/wp2tutor/rag/v1/datatables';const options = { method: 'POST', headers: { 'X-WP-Nonce': '<X-WP-Nonce>', 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ draw: '1', start: '0', length: '25', 'search[value]': 'embedding', 'order[0][column]': '6', 'order[0][dir]': 'desc' })};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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=descSame 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.
Authorizations
Section titled “Authorizations”Request Body
Section titled “Request Body”object
DataTables draw counter. PHP max(1, (int)), default 1. Echoed in the response.
OFFSET. PHP max(0, (int)), default 0.
LIMIT. PHP min(100, max(1, (int))), default 25.
Search. In PHP this becomes $params[‘search’][‘value’].
Column index. In PHP $params[‘order’][0][‘column’]. 1 status, 2 id_chunk, 5 id_post, 6 created_at.
Asc/desc. In PHP $params[‘order’][0][‘dir’]; not ASC → DESC.
Example
draw=1&start=0&length=25&search%5Bvalue%5D=embedding&order%5B0%5D%5Bcolumn%5D=6&order%5B0%5D%5Bdir%5D=descResponses
Section titled “Responses”Same DataTables object as GET.
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 }}