Skip to content

JavaScript Minify API

Overview

Minify JavaScript source code and return a temporary download URL and preview. Body mode is synchronous; URL and file modes submit an asynchronous job.

Endpoint

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

Authentication

Include your API key in the x-api-key header:

x-api-key: YOUR_API_KEY

Input modes

Select a mode with x-source-type:

Mode Behavior
body Sends JavaScript source directly. Processing is synchronous. This is the default mode.
url Submits an asynchronous job to fetch and process a file from a URL.
file Submits an asynchronous job to process a previously uploaded file.

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 Default: body. Values: body, url, file Selects the input mode.
x-tab-space String No No endpoint-specific values Has no effect on minification.

Accepted file extensions

For URL and file modes, the accepted extensions are .txt, .js, and .log.

Request body

Body mode

Send JavaScript source as raw text in the request body.

URL mode

Send a JSON object with a url field:

{
  "url": "https://example.com/script.js"
}

The URL must 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 -X POST "https://api.apidatatools.com/javascript-minify-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: body" \
  --data-raw 'function add(a, b) { return a + b; }'

URL mode

curl -X POST "https://api.apidatatools.com/javascript-minify-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: url" \
  --data-raw '{"url":"https://example.com/script.js"}'

File mode

curl -X POST "https://api.apidatatools.com/javascript-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 body-mode request returns HTTP 200. The file value is a temporary download URL; preview contains a preview of the minified JavaScript.

{
  "request_id": "REQUEST_ID",
  "status": "success",
  "file": "https://downloads.apidatatools.com/temporary-file.js",
  "preview": "function add(a,b){return a+b}"
}

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

Check an asynchronous job with GET https://api.apidatatools.com/jobs/{job_id}. Include your API key in the x-api-key header. A successful status lookup returns HTTP 200.

curl "https://api.apidatatools.com/jobs/JOB_ID" \
  -H "x-api-key: YOUR_API_KEY"

Every status response includes request_id, job_id, status, created_at, and updated_at.

Queued and processing

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": 1760000000,
  "updated_at": 1760000000,
  "message": "Your job is being processed.",
  "retry_after": 2
}

For a processing job, status is "processing"; the other fields have the same shape.

Success

A completed job includes a result object:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "success",
  "created_at": 1760000000,
  "updated_at": 1760000005,
  "result": {
    "status": "success",
    "file": "https://downloads.apidatatools.com/temporary-file.js",
    "preview": "function add(a,b){return a+b}"
  }
}

Failed

A failed job includes an error object. Its details contains the message and may contain additional details:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "failed",
  "created_at": 1760000000,
  "updated_at": 1760000005,
  "error": {
    "code": "JS_MINIFY_ERROR",
    "message": "Failed to minify JavaScript.",
    "details": {
      "message": "Failed to minify JavaScript."
    }
  }
}

Error handling

Error responses use this envelope. Additional fields may appear inside details.

{
  "status": "error",
  "error": "ERROR_CODE",
  "request_id": "REQUEST_ID",
  "details": {
    "message": "Description of the error."
  }
}

The following HTTP statuses and error codes are grounded in the API behavior:

HTTP status Error codes When it can occur
400 INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, MISSING_INPUT_FILE, INVALID_JS, EMPTY_JS, INVALID_UTF8, JS_INPUT_TOO_LARGE, JS_MINIFY_ERROR Invalid mode or body, or a JavaScript input or minification error.
400 INVALID_BODY, INVALID_URL, URL_UNREACHABLE, URL_NOT_OK, INVALID_FILE, FILE_UNAVAILABLE, INVALID_FILE_EXTENSION Invalid asynchronous request body, URL, file reference, or extension.
401 UNAUTHORIZED Authentication failed.
404 USER_NOT_FOUND, UNKNOWN_FUNCTION User or endpoint not found.
413 PAYLOAD_TOO_LARGE, FILE_TOO_LARGE Body or input file exceeds the applicable limit.
429 QUOTA_EXCEEDED, RATE_LIMITED Plan quota or rate limit was exceeded.
500 PLAN_NOT_FOUND, INTERNAL_ERROR, CONFIG_ERROR, PLAN_CONFIG_ERROR Plan configuration, asynchronous job configuration, or request processing failed.

Asynchronous processing failures are reported in the failed job’s status response. Download and output retention periods, as well as body-size, file-size, quota, and rate limits, depend on the plan. See tool limits.

Notes

  • Body mode expects raw JavaScript text; URL and file modes expect JSON request bodies.
  • Download URLs are temporary. Their retention period depends on the plan.
  • A job status lookup requires the job to belong to the authenticated user.