Skip to content

HTML Formatter API

Overview

The HTML Formatter API formats HTML supplied as raw text, a URL, or a pre-uploaded file reference. Body mode runs synchronously; URL and file modes create an asynchronous job.

Endpoint

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

Authentication

Send your API key in the x-api-key header with every request.

Input modes

Mode Behavior
body Sends raw text for synchronous processing. This is the default mode.
url Submits a URL for asynchronous processing.
file Submits a pre-uploaded file reference for asynchronous processing.

Headers

Header names are case-insensitive. The documented lowercase spellings are shown below.

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.

Accepted file extensions

URL and file inputs must use one of these extensions:

  • .txt
  • .html

Request body

Body mode

Send the HTML as raw text in the request body. Body mode is synchronous.

URL mode

Send a JSON object containing the input URL:

{
  "url": "https://example.com/input.html"
}

File mode

Send a JSON object containing the exact storage key returned by the upload workflow:

{
  "file": "S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"
}

Do not add a path prefix to the storage key.

curl examples

Body mode

curl -X POST 'https://api.apidatatools.com/html-formatter-api' \
  -H 'x-api-key: YOUR_API_KEY' \
  --data-raw '<html><body><h1>Hello</h1></body></html>'

URL mode

curl -X POST 'https://api.apidatatools.com/html-formatter-api' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'x-source-type: url' \
  -d '{"url":"https://example.com/input.html"}'

File mode

curl -X POST 'https://api.apidatatools.com/html-formatter-api' \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'x-source-type: file' \
  -d '{"file":"S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"}'

Success responses

Synchronous body mode

A successful synchronous response includes request_id, status, and preview. If the result is file-producing, it also includes file:

{
  "request_id": "REQUEST_ID",
  "status": "success",
  "file": "https://downloads.apidatatools.com/OUTPUT_FILE",
  "preview": "OUTPUT_PREVIEW"
}

If the result is data-producing, the response has no file field; preview contains serialized JSON. The supplied source does not establish which result type this endpoint returns.

Asynchronous URL and file modes

A successfully accepted asynchronous 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 a job with:

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

Include x-api-key on the status request. The response contains request_id, job_id, status, created_at, and updated_at. Timestamps are Unix timestamps.

For queued and processing jobs, the response also contains:

{
  "message": "Your job is being processed.",
  "retry_after": 2
}

For example:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "queued",
  "created_at": 1700000000,
  "updated_at": 1700000000,
  "message": "Your job is being processed.",
  "retry_after": 2
}

A successful job includes a result object:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "success",
  "created_at": 1700000000,
  "updated_at": 1700000002,
  "result": {
    "status": "success",
    "file": "https://downloads.apidatatools.com/OUTPUT_FILE",
    "preview": "OUTPUT_PREVIEW"
  }
}

A failed job includes an error object. Its details may contain additional fields:

{
  "request_id": "REQUEST_ID",
  "job_id": "JOB_ID",
  "status": "failed",
  "created_at": 1700000000,
  "updated_at": 1700000002,
  "error": {
    "code": "DOWNLOAD_FAILED",
    "message": "ERROR_MESSAGE",
    "details": {
      "message": "ERROR_MESSAGE"
    }
  }
}

Example status request:

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

Error handling

Error responses use this envelope:

{
  "status": "error",
  "error": "ERROR_CODE",
  "request_id": "REQUEST_ID",
  "details": {
    "message": "Error description"
  }
}

details may contain additional fields. The following HTTP statuses are established by the supplied backend:

HTTP status Error codes
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
401 UNAUTHORIZED
404 USER_NOT_FOUND, UNKNOWN_FUNCTION
413 PAYLOAD_TOO_LARGE, FILE_TOO_LARGE
429 QUOTA_EXCEEDED, RATE_LIMITED
500 PLAN_NOT_FOUND, INTERNAL_ERROR, CONFIG_ERROR, PLAN_CONFIG_ERROR

The job-status endpoint returns HTTP 400 for its tool errors, including INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, and DDB_ERROR. Errors that occur while an asynchronous job is being processed are reported in the job’s failed status response.

Notes

  • Body-size, file-size, quota, rate, and output-retention limits depend on your plan. See Tool limits.
  • Download URLs are temporary; their availability depends on plan retention limits.