HTML Minify API¶
Overview¶
Minify HTML supplied as raw text, or submit an HTML file by URL or pre-uploaded file reference. Body mode runs synchronously. URL and file modes create asynchronous jobs.
Endpoint¶
| Method | URL |
|---|---|
POST | https://api.apidatatools.com/html-minify-api |
Authentication¶
Include your API key in the x-api-key header:
x-api-key: YOUR_API_KEY
Input modes¶
| Mode | Processing | Input |
|---|---|---|
body | Synchronous | Raw HTML text |
url | Asynchronous | JSON object containing a URL |
file | Asynchronous | JSON object containing a pre-uploaded file reference |
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 | — | API key used to authenticate the request. |
x-source-type | string | No | Default: body. Values: body, url, file. | Selects the input mode. |
Accepted file extensions¶
For URL and file modes, accepted extensions are txt and html.
Request body¶
Body mode¶
Send the HTML as raw text, not as a JSON object.
URL mode¶
Send a JSON object with a url field:
{
"url": "https://example.com/input.html"
}
File mode¶
Send a JSON object with a file field. Use the exact storage key returned by the upload workflow.
{
"file": "S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"
}
curl examples¶
Body mode¶
curl -X POST "https://api.apidatatools.com/html-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: body" \
--data-raw '<html><body><p>Hello</p></body></html>'
URL mode¶
curl -X POST "https://api.apidatatools.com/html-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: url" \
--data-raw '{"url":"https://example.com/input.html"}'
File mode¶
curl -X POST "https://api.apidatatools.com/html-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: file" \
--data-raw '{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}'
Success responses¶
Synchronous body mode¶
A successful synchronous response includes request_id, status, and preview when the result is data. The preview value is serialized JSON.
{
"request_id": "REQUEST_ID",
"status": "success",
"preview": "PREVIEW"
}
For a file-producing result, the response includes request_id, status, file, and preview:
{
"request_id": "REQUEST_ID",
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "PREVIEW"
}
Asynchronous URL and file modes¶
Job creation 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¶
Check a job using the job_id returned when the job was created:
GET https://api.apidatatools.com/jobs/{job_id}
Include the x-api-key header when checking job status. A successful status lookup returns HTTP 200.
Queued and processing jobs have the same response shape:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "queued",
"created_at": 0,
"updated_at": 0,
"message": "Your job is being processed.",
"retry_after": 2
}
The status value is processing while the job is processing.
A successful job status response includes the stored result:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "success",
"created_at": 0,
"updated_at": 0,
"result": {
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "PREVIEW"
}
}
A failed job status response includes an error object:
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "failed",
"created_at": 0,
"updated_at": 0,
"error": {
"code": "ERROR_CODE",
"message": "Error message",
"details": {
"message": "Error message"
}
}
}
Error handling¶
Error responses use this envelope. Additional fields may appear in details.
{
"status": "error",
"error": "ERROR_CODE",
"request_id": "REQUEST_ID",
"details": {
"message": "Error message"
}
}
The following HTTP statuses are established by the request and status handlers:
| HTTP status | Error codes | When it applies |
|---|---|---|
400 | INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, INVALID_BODY, INVALID_URL, URL_UNREACHABLE, URL_NOT_OK, INVALID_FILE, FILE_UNAVAILABLE, INVALID_FILE_EXTENSION | Invalid mode, body, URL, or file input, or an inaccessible or unsupported input. |
400 | DDB_ERROR, FORBIDDEN, INVALID_JOB_ID, JOB_NOT_FOUND | Job-status lookup errors. |
400 | Tool-specific errors | A tool execution error. The specific error code depends on the error. |
401 | UNAUTHORIZED | Authentication context is missing or invalid. |
404 | USER_NOT_FOUND, UNKNOWN_FUNCTION | The user or requested API endpoint was not found. |
413 | PAYLOAD_TOO_LARGE, FILE_TOO_LARGE | The request body or input file exceeds the applicable limit. |
429 | QUOTA_EXCEEDED, RATE_LIMITED | The plan quota or rate limit was exceeded. |
500 | PLAN_NOT_FOUND, CONFIG_ERROR, PLAN_CONFIG_ERROR, INTERNAL_ERROR | Plan configuration is unavailable, async job configuration is unavailable, or an internal error occurred. |
Async jobs can also fail with INVALID_JOB, DOWNLOAD_FAILED, or UPLOAD_FAILED. These appear as the job’s error code in the failed job status response; the job status response does not assign them an HTTP status.
Notes¶
- Body-size, file-size, quota, rate, and download-retention limits depend on your plan. See tool limits.
- Download URLs are temporary; their retention depends on your plan.