XML to Base64 API Documentation¶
Overview¶
The XML to Base64 API converts a valid XML document into a Base64-encoded text file.
It validates the XML structure, encodes it as UTF-8 bytes, and returns the Base64 representation.
This API supports synchronous (body input) and asynchronous (remote URL or uploaded file) modes.
Base URL:
https://api.apidatatools.com/xml-to-base64-api
Endpoint (POST)¶
POST https://api.apidatatools.com/xml-to-base64-api
Headers¶
| Header | Type | Required | Description |
|---|---|---|---|
Content-Type | application/json or text/plain | Yes | Defines the input format. |
x-api-key | string | Yes | Your API key for authentication. |
x-source-type | string | Optional | Defines input mode: body, url, or file. Default is body. |
Accepted File Extensions¶
| Mode | Supported Extensions |
|---|---|
| Body | .xml, .txt, .log |
| URL | .xml, .txt, .log |
| File | .xml, .txt, .log |
Input Example (Body Mode)¶
Header:
x-source-type: body
Content-Type: text/plain
x-api-key: YOUR_API_KEY
Body:
<note>
<to>User</to>
<from>API</from>
<message>Hello World</message>
</note>
Input Example (URL Mode)¶
Header:
x-source-type: url
Content-Type: application/json
x-api-key: YOUR_API_KEY
Body:
{
"url": "https://example.com/sample.xml"
}
Input Example (File Mode)¶
Header:
x-source-type: file
Content-Type: application/json
x-api-key: YOUR_API_KEY
Body:
{
"file": "user_uploads/12345/sample.xml"
}
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/xml-to-base64-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: body" \
-H "Content-Type: text/plain" \
-d '<note><to>User</to><from>API</from><message>Hello</message></note>'
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/xml-to-base64-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: url" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/sample.xml"}'
Asynchronous (Input File)¶
curl -X POST "https://api.apidatatools.com/xml-to-base64-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: file" \
-H "Content-Type: application/json" \
-d '{"file": "user_uploads/12345/sample.xml"}'
Example Response¶
Successful (Body Mode)¶
Status Code: 200 OK
{
"status": "success",
"request_id": "b7f3c5e2-9a3f-4a5c-8b2f-123456789abc",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.txt",
"preview": "PG5vdGU+PHRvPlVzZXI8L3RvPjx..."
}
Async Job Accepted¶
Status Code: 202 Accepted
{
"status": "accepted",
"job_id": "f2b1e5a0-7c4b-4a2e-9e2b-abcdef123456",
"status_url": "https://api.apidatatools.com/jobs/f2b1e5a0-7c4b-4a2e-9e2b-abcdef123456",
"request_id": "b7f3c5e2-9a3f-4a5c-8b2f-123456789abc"
}
Error Handling¶
| Error Code | HTTP Status | Description | Example |
|---|---|---|---|
INVALID_XML | 400 | The XML is malformed or invalid. | {"status":"error","error":"INVALID_XML","details":{"message":"XML validation failed."}} |
BASE64_ENCODING_FAILED | 400 | Failed to encode XML to Base64. | {"status":"error","error":"BASE64_ENCODING_FAILED","details":{"message":"Failed to encode XML to Base64."}} |
INVALID_URL | 400 | Provided URL is invalid or missing. | {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}} |
URL_UNREACHABLE | 400 | The remote URL could not be reached. | {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL"}} |
URL_NOT_OK | 400 | URL returned non-200 HTTP status. | {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}} |
FILE_TOO_LARGE | 413 | File exceeds plan limit. | {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"File exceeds plan limit."}} |
INVALID_FILE_EXTENSION | 400 | File extension not allowed. | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Extension '.pdf' is not allowed"}} |
FILE_UNAVAILABLE | 400 | File not found in storage. | {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file"}} |
EMPTY_BODY | 400 | Request body is empty. | {"status":"error","error":"EMPTY_BODY","details":{"message":"Request body is empty."}} |
PAYLOAD_TOO_LARGE | 413 | Body exceeds plan limit. | {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit"}} |
INTERNAL_ERROR | 500 | Unexpected internal failure. | {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}} |
Async Job Status¶
Endpoint:
GET https://api.apidatatools.com/jobs/{job_id}
Headers:
x-api-key: YOUR_API_KEY
Example Status Response for Async¶
Queued or Processing¶
{
"job_id": "f2b1e5a0-7c4b-4a2e-9e2b-abcdef123456",
"status": "queued",
"message": "Your job is being processed.",
"retry_after": 2,
"created_at": 1712345678,
"updated_at": 1712345678
}
Success¶
{
"job_id": "f2b1e5a0-7c4b-4a2e-9e2b-abcdef123456",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345680,
"result": {
"status": "success",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.txt",
"request_id": "b7f3c5e2-9a3f-4a5c-8b2f-123456789abc",
"preview": "PG5vdGU+PHRvPlVzZXI8L3RvPjx..."
}
}
Failed¶
{
"job_id": "f2b1e5a0-7c4b-4a2e-9e2b-abcdef123456",
"status": "failed",
"created_at": 1712345678,
"updated_at": 1712345680,
"error": {
"code": "INVALID_XML",
"message": "XML validation failed.",
"details": {
"message": "XML validation failed."
}
}
}
Notes for Developers¶
- The API automatically validates XML before encoding. Invalid XML will trigger an error.
- The output file is stored temporarily and accessible via the returned download URL.
- For large XML files or remote sources, use asynchronous mode (
x-source-type: urlorfile). - Each response includes a unique
request_idfor tracking and debugging. - Async jobs can be monitored using the Job Status API until completion.
- Preview data is limited to the first 100 KB of the Base64 output.
- Ensure that your plan limits (body size, file size, retention hours) are respected.