Text Minify API¶
Overview¶
Minify text by collapsing whitespace between content to a single space and removing leading and trailing whitespace. Body mode runs synchronously; URL and file modes run asynchronously.
Endpoint¶
Method: POST
URL: https://api.apidatatools.com/text-minify-api
Authentication¶
Include your API key in the x-api-key header:
x-api-key: YOUR_API_KEY
Input modes¶
| Mode | Behavior |
|---|---|
body | Sends text directly and processes it synchronously. This is the default. |
url | Submits a URL to a .txt file for asynchronous processing. |
file | Submits a pre-uploaded file reference for asynchronous processing. |
Headers¶
Header names are case-insensitive. The spellings below are lowercase.
| Header | Type | Required | Default / values | Description |
|---|---|---|---|---|
x-api-key | String | Yes | Your API key | Authenticates the request. |
x-source-type | String | No | Defaults to body; supported modes: body, url, file | Selects how the input is supplied. |
x-reverse-option | String | No | No default or values documented for this endpoint | Does not affect text minification. |
Accepted file extensions¶
URL and file modes accept .txt files.
Request body¶
Body mode¶
Send the text as the raw request body. Do not wrap it in JSON. A body containing only whitespace is rejected.
URL mode¶
Send a JSON object with a url property:
{
"url": "https://example.com/input.txt"
}
File mode¶
Send a JSON object with a file property 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/text-minify-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--data-raw ' Hello world
This is text. '
URL mode¶
curl --request POST \
--url https://api.apidatatools.com/text-minify-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: url' \
--header 'Content-Type: application/json' \
--data '{"url":"https://example.com/input.txt"}'
File mode¶
curl --request POST \
--url https://api.apidatatools.com/text-minify-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 response returns HTTP 200 and includes a preview and a temporary download URL in file:
{
"request_id": "REQUEST_ID",
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "Hello world This is text."
}
Asynchronous URL and file modes¶
A successful submission 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 with:
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. Timestamps are integers. For queued and processing jobs, the response also includes message and retry_after:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "queued",
"created_at": 1730000000,
"updated_at": 1730000000,
"message": "Your job is being processed.",
"retry_after": 2
}
The processing response has the same shape, with "status": "processing".
A successful job includes its result:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "success",
"created_at": 1730000000,
"updated_at": 1730000002,
"result": {
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "Minified text."
}
}
A failed job includes an error object:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "failed",
"created_at": 1730000000,
"updated_at": 1730000002,
"error": {
"code": "INVALID_TEXT",
"message": "Input contains only whitespace.",
"details": {}
}
}
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."
}
}
Synchronous request errors¶
| HTTP status | Error codes |
|---|---|
400 | INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, INVALID_TEXT, INVALID_UTF8, MISSING_INPUT_FILE, TEXT_MINIFY_ERROR |
401 | UNAUTHORIZED |
404 | USER_NOT_FOUND, UNKNOWN_FUNCTION |
413 | PAYLOAD_TOO_LARGE |
429 | QUOTA_EXCEEDED, RATE_LIMITED |
500 | PLAN_NOT_FOUND, INTERNAL_ERROR |
Asynchronous submission errors¶
| HTTP status | Error codes |
|---|---|
400 | INVALID_BODY, INVALID_URL, URL_UNREACHABLE, URL_NOT_OK, INVALID_FILE, FILE_UNAVAILABLE, INVALID_FILE_EXTENSION, INVALID_SOURCE_TYPE |
413 | FILE_TOO_LARGE |
500 | CONFIG_ERROR, PLAN_CONFIG_ERROR |
Errors returned by the job-status endpoint include INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, and DDB_ERROR; these are returned as HTTP 400 tool errors.
A job that fails during processing reports its failure in the job-status response. Possible processing errors include INVALID_JOB, DOWNLOAD_FAILED, FILE_TOO_LARGE, UPLOAD_FAILED, INTERNAL_ERROR, and text-processing errors such as INVALID_TEXT or INVALID_UTF8.
Notes¶
- Body mode is synchronous. URL and file modes are asynchronous.
- Body-size, file-size, quota, rate, and retention limits depend on your plan. See tool limits.
- Output download URLs are temporary; their retention period depends on your plan.
- Whitespace-only input is rejected. A successful minification collapses whitespace between text to single spaces and removes leading and trailing whitespace.