Skip to content

JavaScript Formatter API Documentation

Overview

The JavaScript Formatter API formats and beautifies JavaScript code. It accepts JavaScript content as input and returns a formatted .js file.
This API supports Body, URL, and File input modes, allowing both synchronous and asynchronous processing.

Base URL:
https://api.apidatatools.com/javascript-formatter-api


Endpoint (POST)

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


Headers

Header Type Required Description
Content-Type application/json Yes Specifies the request content type.
x-api-key string Yes Your API key for authentication.
x-source-type string Optional Defines input mode: body, url, or file. Defaults to body.

Accepted File Extensions

Mode Allowed Extensions
URL / File .txt, .js, .log

Input Example (Body Mode)

function test(){console.log('hello');}

Input Example (URL Mode)

{
  "url": "https://example.com/scripts/sample.js"
}

Input Example (File Mode)

{
  "file": "user_uploads/abcd1234/sample.js"
}

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/javascript-formatter-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: body" \
  -d 'function test(){console.log(\"hello\");}'

Asynchronous (Remote File URL)

curl -X POST "https://api.apidatatools.com/javascript-formatter-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: url" \
  -d '{"url": "https://example.com/scripts/sample.js"}'

Asynchronous (Input File)

curl -X POST "https://api.apidatatools.com/javascript-formatter-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "x-source-type: file" \
  -d '{"file": "user_uploads/abcd1234/sample.js"}'

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "e8a1b2c3-4567-8901-2345-abcdef123456",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123def456.js",
  "preview": "function test() {\n  console.log('hello');\n}"
}

Async Job Accepted

{
  "status": "accepted",
  "job_id": "b7f2c3d4-5678-9012-3456-abcdef789012",
  "status_url": "https://api.apidatatools.com/jobs/b7f2c3d4-5678-9012-3456-abcdef789012",
  "request_id": "e8a1b2c3-4567-8901-2345-abcdef123456"
}

Error Handling

Error Code HTTP Status Description Example
INVALID_JS 400 Input is empty or not a valid string. {"status":"error","error":"INVALID_JS","details":{"message":"JavaScript input must be a non-empty string"}}
JS_FORMAT_ERROR 400 Error occurred during formatting. {"status":"error","error":"JS_FORMAT_ERROR","details":{"message":"Unexpected token"}}
INVALID_URL 400 URL is missing or invalid. {"status":"error","error":"INVALID_URL","details":{"message":"URL must be valid http/https."}}
URL_UNREACHABLE 400 The provided URL could not be reached. {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL"}}
URL_NOT_OK 400 Remote file 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":"Extension '.exe' is not allowed"}}
INVALID_FILE 400 File path missing or invalid. {"status":"error","error":"INVALID_FILE","details":{"message":"Missing or invalid 'file'."}}
FILE_UNAVAILABLE 400 File not found in storage. {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file"}}
PAYLOAD_TOO_LARGE 413 Request body exceeds plan limit. {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds 5120KB limit for your plan."}}
UNKNOWN_FUNCTION 404 Endpoint not recognized. {"status":"error","error":"UNKNOWN_FUNCTION","details":{"message":"Unsupported API endpoint."}}
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 API.

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

Example Status Response for Async

Queued or Processing

{
  "job_id": "b7f2c3d4-5678-9012-3456-abcdef789012",
  "status": "queued",
  "created_at": 1712345678,
  "updated_at": 1712345678,
  "message": "Your job is being processed.",
  "retry_after": 2
}

Successful Completion

{
  "job_id": "b7f2c3d4-5678-9012-3456-abcdef789012",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345690,
  "result": {
    "status": "success",
    "request_id": "e8a1b2c3-4567-8901-2345-abcdef123456",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123def456.js",
    "preview": "function test() {\n  console.log('hello');\n}"
  }
}

Failed Job

{
  "job_id": "b7f2c3d4-5678-9012-3456-abcdef789012",
  "status": "failed",
  "created_at": 1712345678,
  "updated_at": 1712345685,
  "error": {
    "code": "JS_FORMAT_ERROR",
    "message": "Unexpected token",
    "details": {
      "message": "Unexpected token"
    }
  }
}

Notes for Developers

  • This API supports Body, URL, and File input modes.
  • For Body mode, the response is synchronous and includes a direct download link.
  • For URL and File modes, the request is processed asynchronously. You will receive a job_id and status_url to check progress.
  • Each response includes a unique request_id for traceability.
  • Ensure that your input file extensions match the allowed list.
  • The preview field in responses is limited to the first 100 KB of formatted output.
  • Use the Status API to poll job results for asynchronous operations.