Ajax Endpoints

ApproxIt registers AJAX actions on the standard WordPress wp_ajax_* and wp_ajax_nopriv_* hooks. All requests POST to wp-admin/admin-ajax.php.

Authentication and nonces are noted per endpoint. Pro-only endpoints are marked.

Public Endpoint (No Auth)

ax_submit_lead

The single endpoint customers POST to when submitting an estimate.

Registered on: wp_ajax_nopriv_ax_submit_lead and wp_ajax_ax_submit_lead

Auth: None. Anti-spam guards (honeypot, timing token, IP rate limit) substitute for nonce-based auth.

Payload: application/x-www-form-urlencoded or multipart/form-data (for photo uploads in Pro).

FieldRequiredDescription
actionYesMust be ax_submit_lead.
nameYesCustomer name.
emailYesCustomer email (validated server-side).
phoneNoCustomer phone.
addressNoCustomer address.
notesNoCustomer notes (max 1000 chars; truncated server-side).
lead_dataYesJSON-stringified estimate breakdown (services, package, totals).
form_tokenYes (non-local)HMAC-signed timing token from axAjax.formToken.
ax_hp_websiteYesHoneypot field — must be empty.
nonceYesaxAjax.nonce.
ax_photos[]No (Pro)File uploads — only handled when Pro is active.

Response (Success):

JSON

{ 
  "success": true, 
  "data": { "message": "Lead saved" } 
}

Response (Error):

JSON

{ 
  "success": false, 
  "data": "Missing required fields" 
}

Common Error Messages:

  • Missing required fields
  • Submission rejected. Please refresh and try again.
  • Too many requests from your connection. Please try again later.
  • An estimate was recently submitted with this email. Please wait a few minutes before trying again.

Side Effects on Success:

  • Creates an ax_lead post.
  • Saves all the _ax_lead_* meta.
  • Fires the ax_lead_created action.

Admin Endpoints

All admin endpoints require a WordPress user with manage_options capability and a valid nonce (action: ax_leads_action unless otherwise noted).

ax_update_lead_status

Change a lead’s status.

Payload:

Plaintext

action=ax_update_lead_status
nonce=...
lead_id=42
status=contacted

Response: { success: true } or { success: false, data: <error> }.

Side effects: Updates _ax_lead_status, fires ax_lead_status_updated action.

ax_update_lead_score (Pro only)

Manually override a lead’s score.

Payload:

Plaintext

action=ax_update_lead_score
nonce=...
lead_id=42
score=hot

Side effects: Updates _ax_lead_score, sets _ax_lead_score_override to 1.

ax_save_lead_notes (Pro only)

Save admin notes on a lead.

Payload:

Plaintext

action=ax_save_lead_notes
nonce=...
lead_id=42
notes=Called 5/12, left voicemail

ax_delete_lead

Move a lead to the trash.

Payload:

Plaintext

action=ax_delete_lead
nonce=...
lead_id=42

ax_analyze_lead_photos (Pro only)

Run Gemini photo analysis on a lead’s attached photos. Runs synchronously and returns the analysis when complete (can take 10-30s for multiple photos).

Payload:

Plaintext

action=ax_analyze_lead_photos
nonce=...
lead_id=42

Response:

JSON

{
  "success": true,
  "data": {
    "results": {
      "123": { "note": "...", "red_flags": [...], "confidence": 0.85, "thumb": "..." }
    }
  }
}

ax_analyze_property (Pro only)

Run Gemini property research for a lead’s address.

Payload:

Plaintext

action=ax_analyze_property
nonce=...
lead_id=42

ax_send_quote (Pro only)

Trigger a follow-up “quote” email to the customer. Records the timestamp in _ax_lead_quote_sent meta.

ax_test_notification (Pro only)

Send a test SMS or email to verify Twilio / SendGrid integration.

Payload:

Plaintext

action=ax_test_notification
nonce=...
type=sms | email

ax_ai_assist_description (Pro only)

Auto-draft a Business Context description using Gemini, based on site name, estimators, and recent leads.

ax_dismiss_onboarding (Pro only)

Dismiss the Pro onboarding banner on the settings page.

ax_duplicate_estimator (Pro only)

Duplicate an estimator with all its services, packages, and questions.

ax_load_template

Load an industry template into an estimator post, replacing its current services and packages.

Payload:

Plaintext

action=ax_load_template
nonce=...
post_id=42
template=hvac

Side effects: Overwrites _ax_estimator_services, _ax_estimator_packages, _ax_estimator_questions, and the accent color on the target post.

Export Endpoints (admin-post.php)

Two CSV/JSON exports run through admin-post.php instead of admin-ajax.php because they need to set Content-Type headers and stream a file download.

ax_export_leads_csv & ax_export_leads_json

Method: GET to wp-admin/admin-post.php?action=ax_export_leads_csv&_wpnonce=...&filters=...

Auth: manage_options + nonce (action: ax_export_leads).

Response: A file download with Content-Disposition: attachment header.

Pro-Only Public Endpoint

ax_log_abandoned (Pro only)

Endpoint hit by navigator.sendBeacon when a customer leaves the form without submitting. Pro uses this to fire the ax_lead_abandoned action.

Registered on: wp_ajax_nopriv_ax_log_abandoned and wp_ajax_ax_log_abandoned

Auth: None (same anti-spam philosophy as ax_submit_lead).

Adding Your Own AJAX Endpoints

To register custom AJAX actions that fit ApproxIt’s lifecycle:

PHP

add_action( 'ax_leads_ajax_init', function () {
    add_action( 'wp_ajax_my_custom_action', function () {
        if ( ! current_user_can( 'manage_options' ) ) {
            wp_send_json_error( 'Unauthorized' );
        }
        check_ajax_referer( 'ax_leads_action', 'nonce' );

        // Your logic.
        wp_send_json_success( array( 'result' => 'OK' ) );
    } );
} );

The leads dashboard JS exposes a global axLeads.ajaxurl and axLeads.nonce you can reuse. Here is the JavaScript implementation:

JavaScript

fetch(axLeads.ajaxurl, {
    method: 'POST',
    body: new URLSearchParams({
        action: 'my_custom_action',
        nonce:  axLeads.nonce,
        // your params
    }),
}).then(r => r.json()).then(res => console.log(res));

Nonce Reference

Nonce ActionUsed For
ax_submit_leadPublic form submission (frontend-only nonce).
ax_leads_actionAll admin leads-dashboard AJAX (status, notes, score, delete).
ax_save_dataEstimator save (estimator workshop).
ax_load_templateTemplate loading.
ax_test_notificationPro test notification.
ax_dismiss_onboardingPro onboarding banner dismissal.
ax_export_leadsCSV / JSON exports.