CSS Formatter API¶
Overview¶
Formats CSS source text and returns the formatted CSS as a downloadable file with a preview.
Endpoint¶
POST https://api.apidatatools.com/css-formatter-api
Authentication¶
Send your API key in the x-api-key header.
Input modes¶
- body — formats raw CSS text synchronously. This is the default mode.
- url — submits a URL for asynchronous formatting.
- file — submits a pre-uploaded file reference for asynchronous formatting.
Headers¶
Header names are case-insensitive. The spellings below are the documented lowercase forms.
| Header | Type | Required | Default / values | Description |
|---|---|---|---|---|
x-api-key | string | Yes | Your API key | Authenticates the request. |
x-source-type | string | No | body; body, url, or file | Selects the input mode. |
x-tab-space | integer | No | 2; effective value is from 1 to 8 | Sets the indentation width for formatting. Values outside the range are clamped; a non-integer value falls back to 2. |
Accepted file extensions¶
For URL and file modes, the accepted extensions are txt, css, and log.
Request body¶
Body mode¶
Send the CSS as raw text in the request body. No JSON wrapper is used.
URL mode¶
Send a JSON object with a url field:
{
"url": "https://example.com/input.css"
}
The URL must use HTTP or HTTPS and point to a file with an accepted extension.
File mode¶
Send a JSON object with a file field containing the exact storage key returned by the upload workflow:
{
"file": "S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"
}
curl examples¶
Body mode¶
curl --request POST \
--url https://api.apidatatools.com/css-formatter-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--header 'x-tab-space: 4' \
--data-raw 'body{color:red;margin:0}'
URL mode¶
curl --request POST \
--url https://api.apidatatools.com/css-formatter-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: url' \
--header 'Content-Type: application/json' \
--data '{"url":"https://example.com/input.css"}'
File mode¶
curl --request POST \
--url https://api.apidatatools.com/css-formatter-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: file' \
--header 'Content-Type: application/json' \
--data '{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}'
Success responses¶
Synchronous body mode¶
A successful body-mode request returns HTTP 200. The response includes the request ID, success status, a temporary download URL, and a preview.
{
"request_id": "REQUEST_ID",
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "body {\n color: red;\n margin: 0\n}"
}
Asynchronous URL and file modes¶
A successfully accepted URL- or file-mode request returns HTTP 202:
{
"status": "accepted",
"job_id": "JOB_ID",
"status_url": "https://api.apidatatools.com/jobs/JOB_ID",
"request_id": "REQUEST_ID"
}
Async job status¶
Retrieve a job’s status with an authenticated GET request:
curl --request GET \
--url https://api.apidatatools.com/jobs/JOB_ID \
--header 'x-api-key: YOUR_API_KEY'
The status response includes request_id, job_id, status, created_at, and updated_at. The timestamps are Unix timestamps.
- Queued or processing: includes a message and
retry_after.
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "queued",
"created_at": 1700000000,
"updated_at": 1700000000,
"message": "Your job is being processed.",
"retry_after": 2
}
- Success: includes
result, whose value contains the success status, download URL, and preview.
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "success",
"created_at": 1700000000,
"updated_at": 1700000002,
"result": {
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "body {\n color: red\n}"
}
}
- Failed: includes
errorwith a code, message, and details object.
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "failed",
"created_at": 1700000000,
"updated_at": 1700000002,
"error": {
"code": "CSS_FORMAT_ERROR",
"message": "Failed to format CSS.",
"details": {
"message": "Failed to format CSS."
}
}
}
Error handling¶
Error responses use this envelope. Additional fields may appear in details.
{
"status": "error",
"error": "ERROR_CODE",
"request_id": "REQUEST_ID",
"details": {
"message": "Description of the error."
}
}
Request and processing errors¶
| HTTP status | Error code | When it applies |
|---|---|---|
400 | INVALID_SOURCE_TYPE | x-source-type is not body, url, or file. |
400 | INVALID_BODY_ENCODING | The request body cannot be decoded from its encoded representation. |
400 | EMPTY_BODY | The request body is empty. |
400 | CSS_FORMAT_ERROR | CSS formatting fails. |
400 | CSS_INPUT_TOO_LARGE | The CSS input exceeds the formatter’s processing limit. |
400 | INVALID_UTF8 | The input is not valid UTF-8. |
400 | EMPTY_CSS | The CSS input is empty or whitespace only. |
400 | MISSING_INPUT_FILE | The formatter cannot locate its staged input file. |
413 | PAYLOAD_TOO_LARGE | The request body exceeds the limit for the account’s plan. |
404 | UNKNOWN_FUNCTION | The requested API endpoint is unsupported. |
500 | INTERNAL_ERROR | An unexpected processing error occurs. |
URL and file mode errors¶
These errors can occur while creating an asynchronous job.
| HTTP status | Error code | When it applies |
|---|---|---|
400 | INVALID_BODY | The body is not valid JSON or is not a JSON object. |
400 | INVALID_URL | The URL is missing, invalid, or does not use HTTP or HTTPS. |
400 | URL_UNREACHABLE | The URL cannot be reached. |
400 | URL_NOT_OK | The remote server does not return an accepted response. |
400 | INVALID_FILE | The file reference is missing or invalid. |
400 | FILE_UNAVAILABLE | The referenced file cannot be accessed. |
400 | INVALID_FILE_EXTENSION | The input file extension is unsupported. |
400 | INVALID_SOURCE_TYPE | The source type is not url or file for async job creation. |
413 | FILE_TOO_LARGE | The remote or referenced file exceeds the effective limit for the account’s plan and tool. |
500 | CONFIG_ERROR | Async job processing is not configured. |
500 | PLAN_CONFIG_ERROR | The plan’s file-size limit configuration is invalid. |
Authentication and job-status errors¶
| HTTP status | Error code | When it applies |
|---|---|---|
401 | UNAUTHORIZED | Authentication is missing or invalid. |
404 | USER_NOT_FOUND | The authenticated user cannot be found. |
429 | QUOTA_EXCEEDED | The account’s monthly request quota is exhausted. |
429 | RATE_LIMITED | The request rate exceeds the account’s plan limit. |
500 | PLAN_NOT_FOUND | The account’s plan configuration cannot be found. |
400 | INVALID_JOB_ID | The job-status request has no job ID. |
400 | JOB_NOT_FOUND | The requested job cannot be found. |
400 | FORBIDDEN | The job does not belong to the authenticated user. |
400 | DDB_ERROR | The job-status lookup fails. |
Failures during asynchronous processing are reported in the job’s failed status response. They can include DOWNLOAD_FAILED, UPLOAD_FAILED, INVALID_JOB, FILE_TOO_LARGE, and formatter errors.
Notes¶
- Body-mode formatting is synchronous; URL and file modes are asynchronous.
- Request-body, file-size, quota, rate, and download-retention limits depend on the plan. See tool limits.
- Download URLs are temporary; their retention period depends on the plan.