admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('mxchat_app_pairing'), 'i18n' => array( /* translators: %s: minutes:seconds left */ 'expires' => __('Expires in %s', 'mxchat'), 'expired' => __('This code has expired. Show a new one.', 'mxchat'), 'newCode' => __('Show a new code', 'mxchat'), /* translators: %s: phone name */ 'paired' => __('Paired: %s. You can close this page.', 'mxchat'), 'none' => __('No phones paired yet.', 'mxchat'), 'revoke' => __('Revoke', 'mxchat'), 'notAdmin' => __('Signed out: the account is no longer an administrator', 'mxchat'), /* translators: %s: phone name */ 'confirmRevoke' => __('Sign %s out of the MxChat app?', 'mxchat'), 'justNow' => __('Just now', 'mxchat'), /* translators: %d: number of minutes */ 'minutes' => __('%d min ago', 'mxchat'), /* translators: %d: number of hours */ 'hours' => __('%d h ago', 'mxchat'), /* translators: %d: number of days */ 'days' => __('%d days ago', 'mxchat'), ), )); } add_action('admin_post_mxchat_rotate_api_token', 'mxchat_handle_rotate_api_token'); function mxchat_handle_rotate_api_token() { if (!current_user_can('manage_options')) { wp_die(esc_html__('You do not have permission to do this.', 'mxchat')); } check_admin_referer('mxchat_rotate_api_token'); $token = wp_generate_password(48, false, false); update_option(MXCHAT_API_TOKEN_OPTION, $token, false); update_option('mxchat_api_token_rotated_at', time(), false); set_transient('mxchat_api_token_just_rotated', $token, 60); wp_safe_redirect(add_query_arg(array('page' => 'mxchat-api-access', 'rotated' => 1), admin_url('admin.php'))); exit; } /** * Revoke the existing token (sets the option to empty string). */ add_action('admin_post_mxchat_revoke_api_token', 'mxchat_handle_revoke_api_token'); function mxchat_handle_revoke_api_token() { if (!current_user_can('manage_options')) { wp_die(esc_html__('You do not have permission to do this.', 'mxchat')); } check_admin_referer('mxchat_revoke_api_token'); update_option(MXCHAT_API_TOKEN_OPTION, '', false); delete_option('mxchat_api_token_rotated_at'); wp_safe_redirect(add_query_arg(array('page' => 'mxchat-api-access', 'revoked' => 1), admin_url('admin.php'))); exit; } /** * Render the API Access admin page. */ function mxchat_render_api_admin_page() { if (!current_user_can('manage_options')) { wp_die(esc_html__('You do not have permission to access this page.', 'mxchat')); } $stored_token = (string) get_option(MXCHAT_API_TOKEN_OPTION, ''); $token_set = $stored_token !== ''; $just_rotated = get_transient('mxchat_api_token_just_rotated'); delete_transient('mxchat_api_token_just_rotated'); $rotated_query = isset($_GET['rotated']) ? (bool) $_GET['rotated'] : false; $revoked_query = isset($_GET['revoked']) ? (bool) $_GET['revoked'] : false; $rotated_at = (int) get_option('mxchat_api_token_rotated_at', 0); $base_url = trailingslashit(get_rest_url(null, 'mxchat/v1')); $health_url = $base_url . 'health'; $transcripts_u = $base_url . 'transcripts'; $knowledge_url = $base_url . 'knowledge'; $leads_url = $base_url . 'leads'; $plugin_url = plugin_dir_url(dirname(__FILE__)); $app_preview = mxchat_api_page_app_preview(); $masked = $token_set ? substr($stored_token, 0, 4) . str_repeat('•', 24) . substr($stored_token, -4) : ''; $rotated_human = $rotated_at > 0 ? sprintf( /* translators: %s: human-readable elapsed time */ esc_html__('%s ago', 'mxchat'), human_time_diff($rotated_at, current_time('timestamp')) ) : esc_html__('Never', 'mxchat'); ?>

GET
GET
POST
DELETE
GET
DELETE

curl 

curl -H "Authorization: Bearer YOUR_TOKEN" \
  "?role=assistant&knowledge_used=no&since=2026-05-01&limit=50"

curl -X POST -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content":"Q: How do I enable streaming?\nA: ...","source_url":"https://example.com/faq#streaming","content_type":"faq"}' \
  ""

curl -X DELETE -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"source_url":["https://example.com/handbook.pdf","https://example.com/policy-2024.docx"]}' \
  ""

curl -H "Authorization: Bearer YOUR_TOKEN" \
  "?since=2026-05-01T00:00:00Z&per_page=200"

curl -X DELETE -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"session_ids":["sess_abc","sess_def"],"cascade":true}' \
  ""