Skip to content

HTML to Markdown API

Overview

Converts HTML to Markdown. Body mode processes the supplied text synchronously. URL and file modes submit an asynchronous job.

Endpoint

Method URL
POST https://api.apidatatools.com/html-to-markdown-api

Authentication

Include your API key in the x-api-key header on every request:

x-api-key: YOUR_API_KEY

Input modes

Mode How it works
body Send HTML as raw text. Processing is synchronous.
url Submit a URL to an HTML file. Processing is asynchronous.
file Submit the storage key for a pre-uploaded file. Processing is asynchronous.

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 None API key used to authenticate the request.
x-source-type String No Defaults to body. Values: body, url, file. Selects the input mode.

Accepted file extensions

URL and file modes accept these extensions:

  • .txt
  • .html

Request body

Body mode

Send the HTML as raw text in the request body. Do not wrap the HTML in JSON.

URL mode

Send a JSON object containing the URL:

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

File mode

Send a JSON object containing the exact storage key associated with a file uploaded through the upload workflow:

{
  "file": "S3_KEY_RETURNED_BY_THE_UPLOAD_WORKFLOW"
}

Do not add a prefix to the storage key.

curl examples

Body mode

curl -X POST "https://api.apidatatools.com/html-to-markdown-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-to-markdown-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: url" \
  --data-raw '{"url":"https://example.com/input.html"}'

File mode

curl -X POST "https://api.apidatatools.com/html-to-markdown-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 synchronous request returns HTTP 200. The response includes request_id, status, and preview. If the result is file-producing, it also includes file.

Data-producing response:

{
  "request_id": "REQUEST_ID",
  "status": "success",
  "preview": "SERIALIZED_JSON_PREVIEW"
}

File-producing response:

{
  "request_id": "REQUEST_ID",
  "status": "success",
  "file": "TEMPORARY_DOWNLOAD_URL",
  "preview": "PREVIEW"
}

Asynchronous URL and file modes

A successfully accepted job 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 submitted job with GET https://api.apidatatools.com/jobs/{job_id}. Include your API key. The status endpoint returns HTTP 200 for a successful status lookup.

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

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

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

The status value is queued or processing, as applicable.

Success

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": "TEMPORARY_DOWNLOAD_URL",
    "preview": "PREVIEW"
  }
}

Failed

A failed job includes an error object. Its details may include additional information:

{
  "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"
    }
  }
}

Error handling

Errors use this envelope. details may contain additional fields:

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

The following HTTP statuses are established by the API implementation:

HTTP status Error codes Context
400 INVALID_SOURCE_TYPE, INVALID_BODY_ENCODING, EMPTY_BODY Invalid source selection, body encoding, or empty request body.
400 INVALID_BODY, INVALID_URL, URL_UNREACHABLE, URL_NOT_OK, INVALID_FILE, FILE_UNAVAILABLE, INVALID_FILE_EXTENSION Invalid asynchronous request body, URL, or file input.
400 INVALID_JOB_ID, JOB_NOT_FOUND, FORBIDDEN, DDB_ERROR Status endpoint errors.
401 UNAUTHORIZED Authentication failed or authorizer context is missing.
404 USER_NOT_FOUND, UNKNOWN_FUNCTION User or endpoint not found.
413 PAYLOAD_TOO_LARGE, FILE_TOO_LARGE Request body or input file exceeds the applicable limit.
429 QUOTA_EXCEEDED, RATE_LIMITED Plan quota or rate limit reached.
500 PLAN_NOT_FOUND, INTERNAL_ERROR, CONFIG_ERROR, PLAN_CONFIG_ERROR Plan configuration or processing error.

Asynchronous processing can also fail after the job is accepted. Such failures are reported in the job status response; known job error codes include DOWNLOAD_FAILED, FILE_TOO_LARGE, INVALID_JOB, UPLOAD_FAILED, and INTERNAL_ERROR.

Notes

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