Skip to content

Text Minifier API Documentation

Overview

The Text Minifier API removes unnecessary whitespace and blank lines from text content.
It trims leading and trailing spaces, collapses multiple spaces into one, and reduces multiple blank lines to a single blank line while preserving the original line order.

This API supports synchronous and asynchronous operations:

  • Synchronous (Body Mode): Direct text input in the request body.
  • Asynchronous (URL/File Mode): Remote file or uploaded file processing via job queue.

Base URL:
https://api.apidatatools.com/text-minify-api


Endpoint (POST)

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


Headers

Header Type Required Description
x-api-key string Yes API Key for authentication
Content-Type string Yes application/json for body mode
x-source-type string Optional body (default), url, or file

Accepted File Extensions

For URL or File mode, the following extensions are supported:

Mode Allowed Extensions
URL/File .txt

Input Example (Body Mode)

   This is   a   sample text.  \n\n\nIt has   extra spaces.  

Input Example (URL Mode)

{
  "url": "https://example.com/sample.txt"
}

Input Example (File Mode)

{
  "file": "user_uploads/abc123/sample.txt"
}

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/text-minify-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: body" \
  -d '   Hello   world!   \n\nThis   is   spaced.  '

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

curl -X POST "https://api.apidatatools.com/text-minify-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: file" \
  -d '{"file": "uploads/user123/input.txt"}'

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "b7a8c2e3-4f5d-6a7b-8c9d-0e1f2a3b4c5d",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.txt",
  "preview": "Hello world!\n\nThis is spaced."
}

Async Job Accepted (URL/File Mode)

{
  "status": "accepted",
  "job_id": "job-12345-abcde",
  "status_url": "https://api.apidatatools.com/jobs/job-12345-abcde",
  "request_id": "f1e2d3c4-b5a6-7890-1234-56789abcdef0"
}

Error Handling

Error Code HTTP Status Message Example
INVALID_TEXT 400 "Text input must be a non-empty string."
TEXT_MINIFY_ERROR 400 "Failed to minify text."
INVALID_BODY 400 "Body must be valid JSON."
INVALID_URL 400 "Missing or invalid 'url'."
URL_UNREACHABLE 400 "Could not reach URL."
URL_NOT_OK 400 "URL returned HTTP 404, expected 200."
FILE_TOO_LARGE 413 "Remote file exceeds plan limit."
INVALID_FILE_EXTENSION 400 "Invalid or unsupported file extension."
INVALID_FILE 400 "Missing or invalid 'file'."
FILE_UNAVAILABLE 400 "Could not access file."
INVALID_SOURCE_TYPE 400 "Must be 'url' or 'file'."
PAYLOAD_TOO_LARGE 413 "Request body exceeds plan limit."
UNKNOWN_FUNCTION 404 "Unsupported API endpoint."
INTERNAL_ERROR 500 "Failed to process your request."

Async Job Status

To check the status of an asynchronous job, use the Status API:

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

Example Status Response for Async

Queued or Processing

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

Success

{
  "job_id": "job-12345-abcde",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345690,
  "result": {
    "status": "success",
    "request_id": "f1e2d3c4-b5a6-7890-1234-56789abcdef0",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.txt",
    "preview": "Hello world!\n\nThis is spaced."
  }
}

Failed

{
  "job_id": "job-12345-abcde",
  "status": "failed",
  "created_at": 1712345678,
  "updated_at": 1712345680,
  "error": {
    "code": "TEXT_MINIFY_ERROR",
    "message": "Failed to minify text.",
    "details": {
      "message": "Unexpected error while processing text."
    }
  }
}

Notes for Developers

  • The API supports three modes: body, url, and file.
  • For url and file modes, the request is processed asynchronously and returns a job_id.
  • Use the status_url provided in the async response to poll job completion.
  • Each response includes a unique request_id for traceability.
  • The preview field in responses is limited to the first 100 KB of the processed text.