File Converter API

RESTful API for programmatic file conversion operations

Version 1.0 | Base URL: /converter/public/api/v1

POST /api/v1/convert.php

Convert a single file to another format.

Request Parameters

Content-Type: multipart/form-data

Parameter Type Required Description
file File Yes The file to convert (max 5MB)
target_format String Yes Target format (e.g., pdf, csv, xlsx)

Example Request (cURL)

curl -X POST \ -F "[email protected]" \ -F "target_format=pdf" \ https://cosaslearning.com/converter/public/api/v1/convert.php

Success Response

{ "success": true, "data": { "original_name": "document.xlsx", "converted_name": "abc123.pdf", "download_url": "/converter/public/download.php?file=abc123.pdf", "input_size": 15420, "output_size": 28540, "duration_ms": 245.32 } }

POST /api/v1/batch-convert.php

Convert multiple files at once (max 10 files).

Example Request

curl -X POST \ -F "files[][email protected]" \ -F "files[][email protected]" \ -F "target_format=pdf" \ https://cosaslearning.com/converter/public/api/v1/batch-convert.php

Response

{ "success": true, "total": 2, "successful": 2, "failed": 0, "results": [ { "success": true, "original_name": "file1.xlsx", "converted_name": "abc123.pdf", "download_url": "download.php?file=abc123.pdf" }, { "success": true, "original_name": "file2.xlsx", "converted_name": "def456.pdf", "download_url": "download.php?file=def456.pdf" } ] }

GET /api/v1/formats.php

Get list of all supported conversion formats.

Response

{ "success": true, "data": { "conversions": [ {"from": "xlsx", "to": "csv"}, {"from": "xlsx", "to": "pdf"}, {"from": "docx", "to": "pdf"}, {"from": "pdf", "to": "txt"}, ... ], "max_file_size": 5242880, "max_file_size_human": "5 MB" } }

Authentication

POST /api/v1/auth/register.php

// Request { "email": "[email protected]", "password": "securepassword", "name": "John Doe" } // Response { "success": true, "user_id": "user_abc123", "message": "Registration successful" }

POST /api/v1/auth/login.php

// Request { "email": "[email protected]", "password": "securepassword" } // Response { "success": true, "user": { "id": "user_abc123", "email": "[email protected]", "name": "John Doe" }, "token": "64-character-session-token..." }

POST /api/v1/auth/logout.php

Include token in Authorization header:

Authorization: Bearer {token}

User Management

Note: All endpoints require Authorization: Bearer {token} header.

GET /api/v1/user/profile.php

Get current user's profile information.

PUT /api/v1/user/profile.php

Update profile (name, password).

{ "name": "New Name", "password": "newpassword123" // optional }

GET /api/v1/user/history.php

Get conversion history.

Query params: limit (1-100), offset

GET /api/v1/analytics.php

Get conversion analytics (requires API key).

Headers

X-API-Key: your-api-key

Query Parameters

  • start_date - Start date (YYYY-MM-DD)
  • end_date - End date (YYYY-MM-DD)

Rate Limits

Endpoint Limit Window
/api/v1/convert 30 requests 1 minute
/api/v1/batch-convert 10 requests 1 minute
/api/v1/auth/register 5 requests 5 minutes
/api/v1/auth/login 10 requests 1 minute
/api/v1/formats 60 requests 1 minute

Rate Limit Headers

  • X-RateLimit-Limit - Maximum requests allowed
  • X-RateLimit-Remaining - Requests remaining
  • X-RateLimit-Reset - Unix timestamp when limit resets
  • Retry-After - Seconds until you can retry (when rate limited)

Error Responses

// 400 Bad Request { "success": false, "error": "Description of what went wrong" } // 401 Unauthorized { "success": false, "error": "Authentication required" } // 429 Too Many Requests { "success": false, "error": "Rate limit exceeded", "retry_after": 30 } // 500 Server Error { "success": false, "error": "Internal server error" }