JavaScript Minify API Documentation
Overview
The JavaScript Minify API provides an endpoint to minify JavaScript code.
It accepts JavaScript content directly in the request body, or via remote file URL or uploaded file (asynchronous modes).
The tool uses a high-performance JavaScript minifier to remove unnecessary whitespace and comments, producing a compact .js output file.
Endpoint (POST)
POST https://api.apidatatools.com/javascript-minify-api
| Header | Type | Required | Description |
Content-Type | application/json | Yes | Must be application/json for body input. |
x-api-key | string | Yes | Your API key for authentication. |
x-source-type | string | Optional | Determines input mode: body, url, or file. Default is body. |
Accepted File Extensions
| Mode | Allowed Extensions |
| URL/File | .js, .txt, .log |
Input Example (Body Mode)
function greet() { console.log('Hello, world!');}
{
"url": "https://example.com/scripts/app.js"
}
{
"file": "user_uploads/upl_1234567890abcdef/app.js"
}
Example Request
Synchronous (Body Input)
curl -X POST "https://api.apidatatools.com/javascript-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: body" \
-d 'function greet() { console.log(\"Hello, world!\"); }'
Asynchronous (Remote File URL)
curl -X POST "https://api.apidatatools.com/javascript-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: url" \
-d '{"url": "https://example.com/scripts/app.js"}'
curl -X POST "https://api.apidatatools.com/javascript-minify-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "x-source-type: file" \
-d '{"file": "user_uploads/upl_1234567890abcdef/app.js"}'
Example Response
Successful (Body Mode)
{
"status": "success",
"request_id": "b7e4a3d2-9f1b-4e3a-9a1a-3b2c4d5e6f7a",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.js",
"preview": "function greet(){console.log('Hello, world!');}"
}
Async Job Accepted
{
"status": "accepted",
"job_id": "c8b9f1a2-3d4e-5678-9abc-def012345678",
"status_url": "https://api.apidatatools.com/jobs/c8b9f1a2-3d4e-5678-9abc-def012345678",
"request_id": "b7e4a3d2-9f1b-4e3a-9a1a-3b2c4d5e6f7a"
}
Error Handling
| Error Code | HTTP Status | Description | Example |
INVALID_JS | 400 | Input is missing or not a valid JavaScript string. | {"status":"error","error":"INVALID_JS","details":{"message":"JavaScript input must be a non-empty string"}} |
JS_MINIFY_ERROR | 400 | Error occurred during minification. | {"status":"error","error":"JS_MINIFY_ERROR","details":{"message":"Unexpected token"}} |
INVALID_BODY | 400 | Request body is not valid JSON. | {"status":"error","error":"INVALID_BODY","details":{"message":"Body must be valid JSON."}} |
INVALID_URL | 400 | URL is missing or invalid. | {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}} |
URL_UNREACHABLE | 400 | URL could not be reached. | {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL"}} |
URL_NOT_OK | 400 | URL returned non-200 status. | {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}} |
FILE_TOO_LARGE | 413 | File exceeds plan limit. | {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"Remote file exceeds plan limit."}} |
INVALID_FILE_EXTENSION | 400 | File extension not allowed. | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension"}} |
FILE_UNAVAILABLE | 400 | File not accessible in S3. | {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file"}} |
INVALID_SOURCE_TYPE | 400 | Invalid x-source-type header. | {"status":"error","error":"INVALID_SOURCE_TYPE","details":{"message":"Must be 'url' or 'file'."}} |
PAYLOAD_TOO_LARGE | 413 | Request body exceeds plan limit. | {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit"}} |
INTERNAL_ERROR | 500 | Unexpected internal error. | {"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 202 Accepted response.
Endpoint
GET https://api.apidatatools.com/jobs/{job_id}
Example Status Response for Async
Queued or Processing
{
"job_id": "c8b9f1a2-3d4e-5678-9abc-def012345678",
"status": "queued",
"created_at": 1712345678,
"updated_at": 1712345678,
"message": "Your job is being processed.",
"retry_after": 2
}
Successful Completion
{
"job_id": "c8b9f1a2-3d4e-5678-9abc-def012345678",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345690,
"result": {
"status": "success",
"request_id": "b7e4a3d2-9f1b-4e3a-9a1a-3b2c4d5e6f7a",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.js",
"preview": "function greet(){console.log('Hello, world!');}"
}
}
Failed Job
{
"job_id": "c8b9f1a2-3d4e-5678-9abc-def012345678",
"status": "failed",
"created_at": 1712345678,
"updated_at": 1712345680,
"error": {
"code": "JS_MINIFY_ERROR",
"message": "Unexpected token",
"details": {
"message": "Unexpected token"
}
}
}
Notes for Developers
- The API supports three input modes:
- Body Mode (synchronous): Direct JavaScript string input.
- URL Mode (asynchronous): Remote file URL; returns a job ID.
- File Mode (asynchronous): Uploaded file reference; returns a job ID.
- For asynchronous jobs, use the
status_url to poll job progress. - The output file is stored temporarily and accessible via the returned download URL.
- Each response includes a unique
request_id for traceability. - Allowed extensions for this tool:
.js, .txt, .log. - The minified output is served as
application/javascript with .js extension.