Skip to content

XML Formatter API Documentation

Overview

The XML Formatter API validates XML content and returns a formatted, pretty-printed version of the XML.
It supports synchronous processing (direct body input) and asynchronous processing (remote file URL or uploaded file).
The API ensures XML safety using secure parsing and provides a preview of the formatted output.

Base URL:
https://api.apidatatools.com/xml-validator-api


Endpoint (POST)

POST https://api.apidatatools.com/xml-validator-api


Headers

Header Description Required Example
Content-Type Specifies the request content type. Yes application/xml
x-source-type Defines input mode: body, url, or file. Optional (default body) body
x-tab-space Optional indentation spaces for pretty-printing. Must be a positive integer. Optional 4
x-api-key Your API key for authentication Yes abcd1234xyz

Accepted File Extensions

Allowed extensions for this tool: - .xml - .txt - .log


Input Example (Body Mode)

<root>
  <item>Example</item>
</root>

Input Example (URL Mode)

{
  "url": "https://example.com/sample.xml"
}

Input Example (File Mode)

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

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/xml-validator-api" \
  -H "Content-Type: application/xml" \
  -H "x-source-type: body" \
  -H "x-tab-space: 2" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '<root><item>Example</item></root>'

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

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

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "c3f1b2d4-5678-4a9b-9cde-123456789abc",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.xml",
  "preview": "<root>\n  <item>Example</item>\n</root>\n"
}

Async Job Accepted

{
  "status": "accepted",
  "job_id": "job-12345678-90ab-cdef-1234-567890abcdef",
  "status_url": "https://api.apidatatools.com/jobs/job-12345678-90ab-cdef-1234-567890abcdef",
  "request_id": "c3f1b2d4-5678-4a9b-9cde-123456789abc"
}

Error Handling

Error Code HTTP Status Description Example
INVALID_XML 400 XML validation failed due to malformed structure. {"status":"error","error":"INVALID_XML","details":{"message":"XML validation failed.","line":2,"column":5}}
INVALID_BODY_ENCODING 400 Failed to decode base64 body. {"status":"error","error":"INVALID_BODY_ENCODING","details":{"message":"Failed to base64-decode request body."}}
EMPTY_BODY 400 Request body is empty. {"status":"error","error":"EMPTY_BODY","details":{"message":"Request body is empty."}}
INVALID_URL 400 Provided URL is invalid or missing. {"status":"error","error":"INVALID_URL","details":{"message":"URL must be valid http/https."}}
URL_UNREACHABLE 400 Remote URL could not be reached. {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL: Connection timed out"}}
URL_NOT_OK 400 Remote URL returned non-200 HTTP status. {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}}
INVALID_FILE 400 File path missing or invalid. {"status":"error","error":"INVALID_FILE","details":{"message":"Missing or invalid 'file'."}}
FILE_UNAVAILABLE 400 File not accessible in storage. {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file: Not found"}}
INVALID_FILE_EXTENSION 400 Unsupported file extension. {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension: .json"}}
FILE_TOO_LARGE 413 File exceeds plan limit. {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"File exceeds plan limit."}}
PAYLOAD_TOO_LARGE 413 Body exceeds allowed size. {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds 5120KB limit for your plan."}}
INTERNAL_ERROR 500 Unexpected internal error. {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}}

Async Job Status

GET /jobs/{job_id}

Retrieve the status of an asynchronous XML validation job.

Example Status Response for Async

{
  "job_id": "job-12345678-90ab-cdef-1234-567890abcdef",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345689,
  "result": {
    "status": "success",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.xml",
    "request_id": "c3f1b2d4-5678-4a9b-9cde-123456789abc",
    "preview": "<root>\n  <item>Example</item>\n</root>\n"
  }
}

Other possible statuses:

  • "queued" – Job is waiting to be processed.
  • "processing" – Job is currently being executed.
  • "failed" – Job failed; includes error details.
  • "success" – Job completed successfully.

Notes for Developers

  • The API supports all three input modes: body, url, and file.
  • When using asynchronous modes (url or file), a job_id is returned with a status_url for tracking.
  • The x-tab-space header controls indentation for pretty-printed XML output.
  • The response always includes a unique request_id for traceability.
  • For asynchronous jobs, use the Status API (GET /jobs/{job_id}) to check progress or retrieve results.
  • The output file is stored securely and accessible via the returned download URL.
  • The preview field in successful responses contains up to 100 KB of formatted XML for quick inspection.