SQL Minify API¶
Overview¶
Minify SQL text synchronously, or submit a remote URL or uploaded file for asynchronous processing. The API can also rewrite SQL to a different dialect.
Endpoint¶
| Method | URL |
|---|---|
POST | https://api.apidatatools.com/sql-minify-api |
Authentication¶
Include your API key in the x-api-key header on every request:
x-api-key: YOUR_API_KEY
Input modes¶
The x-source-type header selects how the input is supplied:
| Mode | Behavior |
|---|---|
body | Synchronous processing of raw SQL text. This is the default. |
url | Asynchronous processing of a SQL file at a URL. |
file | Asynchronous processing of a previously uploaded SQL file. |
Headers¶
Header names are case-insensitive. The lowercase spellings below are shown for consistency.
| 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-format-mode | String | No | Default: compact. Values: compact, rewrite | Selects minification or dialect rewriting. |
x-input-sql-dialect | String | No | A supported SQL dialect name | Specifies the input dialect. |
x-output-sql-dialect | String | Required for rewrite mode | A supported SQL dialect name | Specifies the target dialect. |
Supported dialect names depend on the SQL dialects available to the service. If x-format-mode is rewrite, an x-output-sql-dialect value is required.
Accepted file extensions¶
For url and file modes, the input file must have one of these extensions:
.sql.txt
Request body¶
body mode¶
Send raw SQL text as the request body. Do not send a JSON wrapper.
SELECT id, name FROM users WHERE active = TRUE;
To rewrite SQL, set x-format-mode: rewrite and provide both the input and output dialect headers as applicable.
url mode¶
Send a JSON object with a url property containing the input file’s URL:
{
"url": "https://example.com/input.sql"
}
file mode¶
Send a JSON object with a file property containing the exact storage key returned by the upload workflow:
{
"file": "S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"
}
Do not add a prefix to the storage key.
cURL examples¶
Raw SQL body¶
curl --request POST \
'https://api.apidatatools.com/sql-minify-api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--data-raw 'SELECT id, name FROM users WHERE active = TRUE;'
URL input¶
curl --request POST \
'https://api.apidatatools.com/sql-minify-api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: url' \
--data-raw '{"url":"https://example.com/input.sql"}'
Previously uploaded file¶
curl --request POST \
'https://api.apidatatools.com/sql-minify-api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: file' \
--data-raw '{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}'
Rewrite to another dialect¶
curl --request POST \
'https://api.apidatatools.com/sql-minify-api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--header 'x-format-mode: rewrite' \
--header 'x-input-sql-dialect: mysql' \
--header 'x-output-sql-dialect: postgres' \
--data-raw 'SELECT id FROM users;'
Success responses¶
Synchronous body mode¶
A successful response has HTTP status 200. SQL output is provided as a file link and a preview:
{
"request_id": "REQUEST_ID",
"status": "success",
"file": "https://downloads.apidatatools.com/OUTPUT_FILE",
"preview": "MINIFIED_SQL_PREVIEW"
}
The preview may be shorter than the full output.
Asynchronous url and file modes¶
A successfully accepted request has HTTP status 202:
{
"status": "accepted",
"job_id": "JOB_ID",
"status_url": "https://api.apidatatools.com/jobs/JOB_ID",
"request_id": "REQUEST_ID"
}
Check the job status endpoint to retrieve the final result or failure.
Async job status¶
Retrieve a job’s status with:
GET https://api.apidatatools.com/jobs/{job_id}
Include x-api-key with the request.
The status response includes request_id, job_id, status, created_at, and updated_at. The status-specific fields are:
Queued or processing¶
For a job that is queued or processing, the response also includes message and retry_after:
{
"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
}
status reflects the current state and may be queued or processing.
Success¶
A completed job includes a result object:
{
"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": "MINIFIED_SQL_PREVIEW"
}
}
Failed¶
A failed job 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": "Description of the failure",
"details": {}
}
}
Error handling¶
Errors use this envelope; details may contain additional fields:
{
"status": "error",
"error": "ERROR_CODE",
"request_id": "REQUEST_ID",
"details": {
"message": "Description of the error"
}
}
The following HTTP statuses are grounded in the request and status handlers:
| HTTP status | Error codes | When it can occur |
|---|---|---|
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 input mode or request body; URL or file validation and access errors. |
400 | MISSING_INPUT_FILE, INVALID_SQL, INVALID_UTF8, EMPTY_SQL, UNSUPPORTED_DIALECT, MISSING_OUTPUT_DIALECT, INVALID_FORMAT_MODE, FORMAT_FAILED, SQL_SYNTAX_ERROR, INTERNAL_FORMATTER_ERROR | SQL input or processing errors. |
400 | INVALID_JOB_ID, DDB_ERROR, JOB_NOT_FOUND, FORBIDDEN | Job status lookup errors. |
401 | UNAUTHORIZED | Authentication failed or authorizer context is unavailable. |
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 applicable 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. |
Some failures occur during asynchronous processing rather than when the job is submitted. These are returned as a job with status: "failed" and an error object, not as the original submission’s HTTP status. Such error codes can include INVALID_JOB, DOWNLOAD_FAILED, UPLOAD_FAILED, FILE_TOO_LARGE, and INTERNAL_ERROR.
Notes¶
- 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.
- URL and file modes return an accepted job response before processing finishes. Use the returned
status_urlto check progress and retrieve the result.