Skip to content

REST API for SEO Audits and Analytics

Call projects, site audits, and analytics with a session cookie in the browser, or with a Bearer token from MCP.

Session Authentication

Secure cookie-based authentication with CSRF protection

RESTful Design

Clean, predictable REST API with JSON responses

Rate Limiting

Subscription-based rate limiting with real-time tracking

Real-time Updates

WebSocket support for live audit progress and notifications

Feature Gating

Subscription tier-based feature access and usage tracking

Bearer tokens

Browser calls use a session cookie and CSRF. MCP and token clients send Authorization Bearer.

JavaScript SDK

Our JavaScript SDK makes it even easier to integrate with the Cool Web Tool API. Install the package via npm and start using it in your application.

// Installation
npm install @coolwebtool/api-client

// Usage with session-based authentication
import { CoolWebToolAPI } from '@coolwebtool/api-client';

// Initialize the client (automatically handles CSRF tokens and cookies)
const api = new CoolWebToolAPI({
  baseURL: 'https://api.coolwebtool.com',
  credentials: 'include', // Include cookies for session auth
});

// Example: Get current user session
async function getCurrentUser() {
  try {
    const session = await api.auth.getSession();
    if (process.env.NODE_ENV === 'development') {
      console.log('Current user:', session.user);
    }
    return session.user;
  } catch (error) {
    console.error('Not authenticated:', error);
    // Redirect to login
    window.location.href = '/accounts/login/';
  }
}

// Example: Create a new project
async function createProject(projectData) {
  try {
    const project = await api.projects.create({
      name: projectData.name,
      domain: projectData.domain,
      description: projectData.description,
    });

    if (process.env.NODE_ENV === 'development') {
      console.log('Project created:', project);
    }
    return project;
  } catch (error) {
    if (error.status === 403) {
      console.error('Feature not available in current plan');
      // Show upgrade modal
    } else {
      console.error('Error creating project:', error);
    }
  }
}

// Example: Run SEO audit
async function runSiteAudit(projectId, url) {
  try {
    const audit = await api.projects.siteAudits.create(projectId, {
      url: url,
      auditType: 'comprehensive',
    });

    if (process.env.NODE_ENV === 'development') {
      console.log('Audit started:', audit);
    }

    // Poll for completion
    const result = await api.projects.siteAudits.waitForCompletion(
      projectId,
      audit.auditId
    );

    if (process.env.NODE_ENV === 'development') {
      console.log('Audit completed:', result);
    }
    return result;
  } catch (error) {
    console.error('Audit failed:', error);
  }
}

// Example: Get analytics metrics
async function getAnalytics(period = '30d') {
  try {
    const metrics = await api.analytics.getMetrics({ period });
    const performance = await api.analytics.getPerformance({ period });

    return {
      overview: metrics.overview,
      performance: performance.metrics,
      trends: performance.trends,
    };
  } catch (error) {
    console.error('Error fetching analytics:', error);
  }
}