API Documentation

Complete API reference for the Tools Platform

Authentication

All API endpoints require Bearer token authentication

Include the Bearer token in the Authorization header:

Authorization: Bearer YOUR_TOKEN_HERE

Tokens can be generated from the admin panel. Contact your administrator for access.

POST /api/csv-to-xlsx

Convert CSV file to XLSX format

Request

Content-Type: multipart/form-data

  • file (required): CSV file to convert

Response

{
  "jobId": "string",
  "status": "queued"
}

Example

curl -X POST https://tools.setabayt.com/api/csv-to-xlsx \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "file=@data.csv"

After submission, use the jobId to check the job status. You can use either:

  • GET /api/jobs/[jobId] - Polling method (check status manually)
  • GET /api/jobs/[jobId]/stream - SSE method (real-time updates, recommended)

POST /api/compress-image

Compress image with configurable quality

Request

Content-Type: multipart/form-data

  • file (required): Image file (JPEG, PNG, WebP)

Query Parameters:

  • quality (optional): Quality 1-100 (default: 80)
  • format (optional): Output format - jpeg, png, webp (default: jpeg)

Response

{
  "jobId": "string",
  "status": "queued"
}

Example

curl -X POST "https://tools.setabayt.com/api/compress-image?quality=85&format=jpeg" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "file=@image.jpg"

GET /api/jobs/[jobId]

Check job status and get result (Polling method)

Response

{
  "status": "queued" | "processing" | "completed" | "failed",
  "downloadUrl": "string", // Only when status is "completed"
  "error": "string" // Only when status is "failed"
}

Example

curl -X GET https://tools.setabayt.com/api/jobs/JOB_ID \
  -H "Authorization: Bearer YOUR_TOKEN"

Note: For real-time updates, use the SSE endpoint instead (see below).

GET /api/jobs/[jobId]/stream

Real-time job status updates using Server-Sent Events (SSE) - Recommended

Overview

SSE endpoint provides real-time job status updates without polling. The server pushes updates to the client as they occur.

Response Format

Server-Sent Events stream:

data: {"type":"connected","jobId":"abc123"}

data: {"type":"status","status":"queued","jobId":"abc123"}

data: {"type":"status","status":"processing","jobId":"abc123"}

data: {"type":"status","status":"completed","jobId":"abc123","downloadUrl":"/api/jobs/abc123/download"}

Event Types

  • connected: SSE connection established
  • status: Job status update
  • error: Error occurred

cURL Example

curl -N -H "Authorization: Bearer YOUR_TOKEN" \
  https://tools.setabayt.com/api/jobs/JOB_ID/stream

-N flag disables buffering for real-time output

JavaScript Example

const eventSource = new EventSource(
  `https://tools.setabayt.com/api/jobs/${jobId}/stream`,
  {
    headers: {
      'Authorization': 'Bearer YOUR_TOKEN'
    }
  }
)

eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data)
  console.log('Status:', data.status)
  
  if (data.status === 'completed' && data.downloadUrl) {
    // Download the file
    window.location.href = data.downloadUrl
    eventSource.close()
  }
}

eventSource.onerror = (error) => {
  console.error('SSE error:', error)
  eventSource.close()
}

Using the Helper Function

For easier integration, use the provided helper function:

import { watchJob } from '@/lib/job-watcher'

const cleanup = watchJob(jobId, {
  onUpdate: (status) => {
    if (status.status === 'completed' && status.downloadUrl) {
      window.location.href = status.downloadUrl
    }
  },
  onError: (error) => {
    console.error('Error:', error)
  },
  onComplete: () => {
    console.log('Job completed')
  }
})

// Cleanup when done
// cleanup()

The helper function automatically uses SSE if available, otherwise falls back to polling.

Advantages over Polling

  • Real-time updates (no delay)
  • Single connection (less server load)
  • Automatic reconnection on errors
  • More efficient network usage

GET /api/jobs/[jobId]/download

Download completed job result

Request

Download the result file when job status is "completed"

Response

Binary file (XLSX for CSV conversion, image for compression)

Example

curl -X GET https://tools.setabayt.com/api/jobs/JOB_ID/download \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -o output.xlsx

GET /api/health

Health check endpoint (no authentication required)

{
  "status": "ok"
}