Skip to content

CSS Minify API Documentation

Overview

The CSS Minify API allows developers to compress and minify CSS content efficiently.
It removes unnecessary whitespace, comments, and formatting to produce a compact CSS output suitable for production environments.

This API supports three input modes:

  • Body Mode – Directly send CSS content in the request body.
  • URL Mode – Provide a remote file URL for asynchronous processing.
  • File Mode – Use a previously uploaded file for asynchronous processing.

The API returns a downloadable .css file containing the minified CSS and a short preview snippet.


Endpoint (POST)

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

Headers

Header Type Required Description
Content-Type application/json Yes Defines the request body format.
x-source-type body | url | file Optional Determines input mode. Defaults to body.
x-api-key <API_KEY> Yes Your API key for authentication abcd1234xyz

Accepted File Extensions

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

Input Example (Body Mode)

body { color: red; } /* comment */

Input Example (URL Mode)

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

Input Example (File Mode)

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

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/css-minify-api" \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: body" \
  -d 'body { color: red; } /* comment */'

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

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

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "b1f2c3d4-5678-90ab-cdef-1234567890ab",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.css",
  "preview": "body{color:red}"
}

Async Job Accepted (URL or File Mode)

{
  "status": "accepted",
  "job_id": "job_1234567890abcdef",
  "status_url": "https://api.apidatatools.com/jobs/job_1234567890abcdef",
  "request_id": "b1f2c3d4-5678-90ab-cdef-1234567890ab"
}

Error Handling

Error Code HTTP Status Description Example
EMPTY_CSS 400 The CSS input is empty or whitespace only. {"status":"error","error":"EMPTY_CSS","details":{"message":"CSS input is empty."}}
CSS_MINIFY_ERROR 400 Failed to minify CSS due to invalid syntax or internal error. {"status":"error","error":"CSS_MINIFY_ERROR","details":{"message":"Failed to minify CSS."}}
INVALID_URL 400 The provided URL is invalid or missing. {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}}
URL_UNREACHABLE 400 The remote URL could not be reached. {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL."}}
URL_NOT_OK 400 The remote URL did not return HTTP 200. {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}}
FILE_TOO_LARGE 413 The file exceeds the plan’s maximum allowed size. {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"File exceeds plan limit."}}
INVALID_FILE_EXTENSION 400 The file extension is not supported. {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension."}}
INVALID_SOURCE_TYPE 400 The x-source-type header is invalid. {"status":"error","error":"INVALID_SOURCE_TYPE","details":{"message":"Must be 'url' or 'file'."}}
INTERNAL_ERROR 500 Unexpected internal error occurred. {"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 returned in the accepted response.

Endpoint

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

Example Status Response for Async

Queued / Processing

{
  "job_id": "job_1234567890abcdef",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2,
  "created_at": 1712345678,
  "updated_at": 1712345678
}

Success

{
  "job_id": "job_1234567890abcdef",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345690,
  "result": {
    "status": "success",
    "request_id": "b1f2c3d4-5678-90ab-cdef-1234567890ab",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.css",
    "preview": "body{color:red}"
  }
}

Failed

{
  "job_id": "job_1234567890abcdef",
  "status": "failed",
  "created_at": 1712345678,
  "updated_at": 1712345680,
  "error": {
    "code": "CSS_MINIFY_ERROR",
    "message": "Failed to minify CSS.",
    "details": {
      "message": "Failed to minify CSS."
    }
  }
}

Notes for Developers

  • The API automatically detects the mode based on the x-source-type header.
  • For Body Mode, the response is synchronous and returns immediately.
  • For URL and File Modes, the request is processed asynchronously, and a job_id is returned.
  • Use the provided status_url to poll job completion.
  • Each response includes a unique request_id for traceability.
  • The output file is stored temporarily and accessible via the returned download URL.
  • Ensure that remote URLs are publicly accessible via HTTP/HTTPS and have valid extensions (.css, .txt, .log).
  • Empty or invalid CSS input will trigger an EMPTY_CSS error.