JavaScript Formatter API¶
Overview¶
Format JavaScript source code with the JavaScript Formatter API. Body mode processes the supplied text synchronously. URL and file modes submit an asynchronous job.
Endpoint¶
POST https://api.apidatatools.com/javascript-formatter-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 JavaScript 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 lowercase spellings below are used in this reference.
| Header | Type | Required | Default / values | Description |
|---|---|---|---|---|
x-api-key | String | Yes | Your API key | Authenticates the request. |
x-source-type | String | No | body; body, url, or file | Selects the input mode. |
x-tab-space | Integer | No | 2; effective range 1–8 | Sets the indentation size when formatting JavaScript. Values outside the range are limited to the range; a value that cannot be parsed as an integer uses 2. |
Accepted file extensions¶
For URL and file modes, the input file must use one of these extensions:
.txt.js.log
Request body¶
Body mode¶
Send the JavaScript source as raw text. An empty request body is rejected.
URL mode¶
Send a JSON object with a url property:
{"url":"https://example.com/input.js"}
File mode¶
Send a JSON object with a file property containing the exact storage key associated with a file uploaded through the upload workflow:
{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}
curl examples¶
Body mode¶
curl --request POST 'https://api.apidatatools.com/javascript-formatter-api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--header 'x-tab-space: 4' \
--data-binary 'function greet(name){return "Hello, "+name;}'
URL mode¶
curl --request POST 'https://api.apidatatools.com/javascript-formatter-api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: url' \
--header 'Content-Type: application/json' \
--data '{"url":"https://example.com/input.js"}'
File mode¶
curl --request POST 'https://api.apidatatools.com/javascript-formatter-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 body-mode response has HTTP status 200. It includes the request ID, success status, a temporary download URL in file, and a text preview.
{
"request_id": "REQUEST_ID",
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "function greet(name) {\n return \"Hello, \" + name;\n}"
}
Asynchronous URL and file modes¶
A successfully accepted URL- or file-mode request has HTTP status 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:
curl --request GET 'https://api.apidatatools.com/jobs/JOB_ID' \
--header 'x-api-key: YOUR_API_KEY'
The status endpoint returns the job ID, status, request ID, and creation and update timestamps. While a job is queued or processing, the response includes a 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 same shape applies when status is processing.
When a job succeeds, the response includes 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": "function greet(name) {\n return \"Hello, \" + name;\n}"
}
}
When a job fails, the response includes an error object. Its details may contain additional error information.
{
"request_id": "REQUEST_ID",
"job_id": "JOB_ID",
"status": "failed",
"created_at": 1730000000,
"updated_at": 1730000002,
"error": {
"code": "DOWNLOAD_FAILED",
"message": "Error connecting to URL",
"details": {
"message": "Error connecting to URL"
}
}
}
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"
}
}
HTTP errors¶
| HTTP status | Error codes | When it applies |
|---|---|---|
400 | INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY, INVALID_UTF8, EMPTY_JS, INVALID_JS, JS_FORMAT_ERROR, JS_INPUT_TOO_LARGE | Invalid source type or body encoding, empty input, invalid JavaScript input, invalid UTF-8, or a formatter processing error. Tool execution errors are returned with HTTP 400. |
400 | INVALID_BODY, INVALID_URL, URL_UNREACHABLE, URL_NOT_OK, INVALID_FILE, FILE_UNAVAILABLE, INVALID_FILE_EXTENSION, CONFIG_ERROR is not included here; see 500 | Invalid asynchronous request body, URL or file input, unreachable or unsuccessful URL, or unsupported extension. |
400 | INVALID_JOB_ID, DDB_ERROR, JOB_NOT_FOUND, FORBIDDEN | A status request is missing a job ID, cannot query the job, refers to a missing job, or does not have access to that job. |
401 | UNAUTHORIZED | Authentication is missing or invalid. |
404 | USER_NOT_FOUND, UNKNOWN_FUNCTION | The authenticated user or requested endpoint is not found. |
413 | PAYLOAD_TOO_LARGE | A synchronous request body exceeds the limit for the plan. |
413 | FILE_TOO_LARGE | An asynchronous URL or file input exceeds the effective file limit. |
429 | QUOTA_EXCEEDED, RATE_LIMITED | The plan quota is exhausted or the request rate limit is exceeded. |
500 | PLAN_NOT_FOUND, INTERNAL_ERROR, CONFIG_ERROR, PLAN_CONFIG_ERROR | Plan configuration or service processing failed, or asynchronous job configuration is unavailable or invalid. |
Asynchronous processing failures such as DOWNLOAD_FAILED, UPLOAD_FAILED, and FILE_TOO_LARGE are reported in the job’s failed status response; they are not the HTTP status of the original 202 acceptance response.
Notes¶
- Body mode is synchronous. URL and file modes are asynchronous.
- Request-body and file-size limits, quotas, and rate limits depend on the plan. See tool limits.
- Output download URLs are temporary. Their retention period depends on the plan.