Skip to content

Base64 Encoder API Documentation

Overview

The Base64 Encoder API converts any textual input into its Base64-encoded representation.
It supports three input modes:

  • Body Mode: Direct text input in the request body.
  • URL Mode: Remote file accessible via HTTP/HTTPS.
  • File Mode: Previously uploaded file stored in the system.

The API returns a Base64-encoded file (.txt) and a short preview of the encoded content.


Endpoint (POST)

POST https://api.apidatatools.com/base64-encoder-api

Headers

Header Description Required Example
Content-Type MIME type of the request body Yes application/json
x-source-type Input source type: body, url, or file Optional (default: body) body
x-api-key API key Yes <api_key>

Accepted File Extensions

This tool accepts the following file extensions when using URL or File mode:

["txt", "log"]


Input Example (Body Mode)

Hello World

Input Example (URL Mode)

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

Input Example (File Mode)

{
  "file": "user123/uploads/sample.txt"
}

Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/base64-encoder-api" \
  -H "Content-Type: application/json" \
  -H "x-source-type: body" \
  -H "x-api-key: YOUR_API_KEY" \
  -d 'Encode this text'

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

curl -X POST "https://api.apidatatools.com/base64-encoder-api" \
  -H "Content-Type: application/json" \
  -H "x-source-type: file" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"file": "user123/uploads/input.txt"}'

Example Response

Successful (Body Mode)

{
  "request_id": "c9a3b2f1-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "success",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.txt",
  "preview": "SGVsbG8gV29ybGQh..."
}

Async Job Accepted

{
  "status": "accepted",
  "job_id": "job-12345678-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status_url": "https://api.apidatatools.com/jobs/job-12345678-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "request_id": "c9a3b2f1-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

Error Handling

Error Code HTTP Status Description Example
BASE64_ENCODING_FAILED 400 Failed to encode input to Base64 {"status":"error","error":"BASE64_ENCODING_FAILED","details":{"message":"Failed to encode to Base64."}}
INVALID_BODY 400 Body must be valid JSON {"status":"error","error":"INVALID_BODY","details":{"message":"Body must be valid JSON."}}
INVALID_URL 400 Missing or invalid URL {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}}
URL_UNREACHABLE 400 Could not reach the provided URL {"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":"Remote file exceeds plan limit."}}
INVALID_FILE_EXTENSION 400 Unsupported file extension {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension"}}
FILE_UNAVAILABLE 400 File not accessible in storage {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file"}}
INVALID_SOURCE_TYPE 400 Source type must be url or file {"status":"error","error":"INVALID_SOURCE_TYPE","details":{"message":"Must be 'url' or 'file'."}}
PAYLOAD_TOO_LARGE 413 Request body exceeds plan limit {"status":"error","error":"PAYLOAD_TOO_LARGE","details":{"message":"Request body exceeds limit"}}
INTERNAL_ERROR 500 Unexpected internal error {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}}

Async Job Status

To check the status of an asynchronous job (URL or File mode), use the Status API:

Endpoint

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

Example Status Response for Async

{
  "job_id": "job-12345678-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345689,
  "result": {
    "request_id": "c9a3b2f1-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "status": "success",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.txt",
    "preview": "U29tZSBiYXNlNjQgZW5jb2RlZCBjb250ZW50..."
  }
}

If the job is still processing:

{
  "job_id": "job-12345678-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2
}

If the job failed:

{
  "job_id": "job-12345678-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "status": "failed",
  "error": {
    "code": "BASE64_ENCODING_FAILED",
    "message": "Failed to encode to Base64.",
    "details": {"message": "Invalid input encoding"}
  }
}


Notes for Developers

  • The API supports synchronous and asynchronous operations depending on x-source-type.
  • For large files or remote URLs, use asynchronous mode to avoid timeouts.
  • Each response includes a unique request_id for tracking and logging.
  • The preview field contains the first 100 KB of the encoded output.
  • The full encoded file is stored securely and accessible via the returned download URL.
  • Use the Status API to poll job progress when using URL or File mode.
  • Ensure proper file extension validation before submitting requests.