Skip to content

CSS Formatter API Documentation

Overview

The CSS Formatter API formats and beautifies CSS code with customizable indentation.
It supports direct text input, remote file URLs, and uploaded files.
The API returns a formatted CSS file with a preview snippet and a downloadable link.

Base URL:
https://api.apidatatools.com/css-formatter-api


Endpoint (POST)

POST https://api.apidatatools.com/css-formatter-api


Headers

Header Type Required Description
x-api-key string Yes Your API key for authentication
x-tab-space integer No Number of spaces for indentation (default: 2)
x-source-type string No Input source type: body, url, or file (default: body)
Content-Type string Yes Must be application/json for body or metadata requests

Accepted File Extensions

Mode Supported Extensions
URL / File .txt, .css, .log

Input Example (Body Mode)

body{color:red;background:#fff;}

Input Example (URL Mode)

{
  "url": "https://example.com/styles/main.css"
}

Input Example (File Mode)

{
  "file": "user_uploads/upl_123abc456def/styles.css"
}

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/css-formatter-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-tab-space: 4" \
  -H "Content-Type: application/json" \
  -d 'color:red;background:#fff;'

Asynchronous (Remote File URL)

curl -X POST "https://api.apidatatools.com/css-formatter-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: url" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/styles/main.css"}'

Asynchronous (Input File)

curl -X POST "https://api.apidatatools.com/css-formatter-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: file" \
  -H "Content-Type: application/json" \
  -d '{"file": "user_uploads/upl_123abc456def/styles.css"}'

Example Response

Successful (Body Mode)

Status Code: 200 OK

{
  "status": "success",
  "request_id": "b3e1a2f4-9c8d-4a7b-8f3a-1f2b3c4d5e6f",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123def456.css",
  "preview": "body {\n  color: red;\n  background: #fff;\n}"
}

Async Job Accepted (URL or File Mode)

Status Code: 202 Accepted

{
  "status": "accepted",
  "job_id": "job_123e4567-e89b-12d3-a456-426614174000",
  "status_url": "https://api.apidatatools.com/jobs/job_123e4567-e89b-12d3-a456-426614174000",
  "request_id": "b3e1a2f4-9c8d-4a7b-8f3a-1f2b3c4d5e6f"
}

Error Handling

Error Code HTTP Status Message Example
EMPTY_CSS 400 CSS input is empty. {"status":"error","error":"EMPTY_CSS","details":{"message":"CSS input is empty."}}
CSS_FORMAT_ERROR 400 Failed to format CSS. {"status":"error","error":"CSS_FORMAT_ERROR","details":{"message":"Failed to format CSS."}}
INVALID_BODY 400 Body must be valid JSON. {"status":"error","error":"INVALID_BODY","details":{"message":"Body must be valid JSON."}}
INVALID_URL 400 Missing or invalid 'url'. {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}}
URL_UNREACHABLE 400 Could not reach URL. {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL"}}
URL_NOT_OK 400 URL returned non-200 response. {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}}
FILE_TOO_LARGE 413 File exceeds plan limit. {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"File exceeds plan limit."}}
INVALID_FILE_EXTENSION 400 Invalid or unsupported file extension. {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension"}}
FILE_UNAVAILABLE 400 Could not access file. {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file"}}
INTERNAL_ERROR 500 Failed to process your request. {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}}

Async Job Status

To check the status of an asynchronous job, use the status_url provided in the 202 Accepted response.

Endpoint:
GET https://api.apidatatools.com/jobs/{job_id}

Example Status Response for Async

Queued or Processing

{
  "job_id": "job_123e4567-e89b-12d3-a456-426614174000",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2,
  "created_at": 1712345678,
  "updated_at": 1712345678
}

Successful Completion

{
  "job_id": "job_123e4567-e89b-12d3-a456-426614174000",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345690,
  "result": {
    "status": "success",
    "request_id": "b3e1a2f4-9c8d-4a7b-8f3a-1f2b3c4d5e6f",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123def456.css",
    "preview": "body {\n  color: red;\n  background: #fff;\n}"
  }
}

Failed Job

{
  "job_id": "job_123e4567-e89b-12d3-a456-426614174000",
  "status": "failed",
  "created_at": 1712345678,
  "updated_at": 1712345680,
  "error": {
    "code": "CSS_FORMAT_ERROR",
    "message": "Failed to format CSS.",
    "details": {
      "message": "Failed to format CSS."
    }
  }
}

Notes for Developers

  • The API supports three input modes:
  • body: Direct CSS text (synchronous)
  • url: Remote file URL (asynchronous)
  • file: Uploaded file reference (asynchronous)
  • For asynchronous jobs, a job_id is returned immediately. Use the Status API to check progress.
  • The formatted file is stored temporarily and accessible via the returned file URL.
  • The preview field contains the first 100 KB of the formatted CSS for quick inspection.
  • The x-tab-space header allows customization of indentation width.
  • Always include a valid x-api-key header for authentication.
  • For large files or remote URLs, prefer asynchronous processing to avoid timeouts.