Skip to content

CSV to Base64 API Documentation

Overview

The CSV to Base64 API converts CSV data into a Base64-encoded text file.
It supports synchronous processing for direct body input and asynchronous processing for remote file URLs or uploaded files.
This API ensures accurate CSV parsing with optional header and delimiter control.


Endpoint (POST)

POST https://api.apidatatools.com/csv-to-base64-api


Headers

Header Type Description
Content-Type string Must be text/plain or application/json depending on input mode
x-source-type string Defines input mode: body, url, or file
x-has-header string Optional. Set to false or 0 if CSV has no header row
x-delimiter string Optional. Custom delimiter (e.g., ,, ;, |) default ,
x-api-key string Your API key for authentication.

Accepted File Extensions

This tool accepts the following file extensions for URL or file mode: - .txt - .csv - .log


Input Example (Body Mode)

name,age,city
Alice,30,New York
Bob,25,London

Headers:

x-source-type: body
x-has-header: true
x-api-key : API_KEY


Input Example (URL Mode)

{
  "url": "https://example.com/data/sample.csv"
}

Headers:

x-source-type: url
x-has-header: true
x-api-key : API_KEY


Input Example (File Mode)

{
  "file": "user_uploads/abc123/sample.csv"
}

Headers:

x-source-type: file
x-has-header: true
x-api-key : API_KEY


Example Request

Synchronous (Body Input)

curl -X POST "https://api.apidatatools.com/csv-to-base64-api" \
  -H "x-source-type: body" \
  -H "x-has-header: true" \
  -H "Content-Type: text/plain" \
  -H "x-api-key: YOUR_API_KEY" \
  --data "name,age\nAlice,30\nBob,25"

Asynchronous (Remote File URL)

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

Asynchronous (Input File)

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

Example Response

Successful (Body Mode)

{
  "status": "success",
  "request_id": "d4f8e2b1-9a3c-4b2e-9b6e-7e2a9c3f1a2b",
  "file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.txt",
  "preview": "U29tZUJhc2U2NFByZXZpZXc="
}

Async Job Accepted

{
  "status": "accepted",
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status_url": "https://api.apidatatools.com/jobs/a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "request_id": "d4f8e2b1-9a3c-4b2e-9b6e-7e2a9c3f1a2b"
}

Error Handling

Error Code HTTP Status Description Example
INVALID_CSV 400 CSV content is empty or invalid {"status":"error","error":"INVALID_CSV","details":{"message":"Empty CSV content."}}
CSV_TO_BASE64_FAILED 400 Failed to encode CSV to Base64 {"status":"error","error":"CSV_TO_BASE64_FAILED","details":{"message":"Failed to encode CSV as Base64."}}
INVALID_BODY_ENCODING 400 Request body could not be base64-decoded {"status":"error","error":"INVALID_BODY_ENCODING","details":{"message":"Failed to base64-decode request body."}}
EMPTY_BODY 400 Request body is missing {"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."}}
INVALID_URL 400 URL missing or invalid {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}}
URL_UNREACHABLE 400 Remote file cannot be reached {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL."}}
URL_NOT_OK 400 Remote file returned non-200 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":"Invalid or unsupported file extension."}}
CONFIG_ERROR 500 Missing configuration for async jobs {"status":"error","error":"CONFIG_ERROR","details":{"message":"JOBS_TABLE or JOBS_QUEUE_URL environment variables not set."}}
INTERNAL_ERROR 500 Unexpected server error {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}}

Async Job Status

To check the status of an asynchronous job, use the Status API:

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

Example Status Response for Async

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "success",
  "created_at": 1712345678,
  "updated_at": 1712345689,
  "result": {
    "request_id": "d4f8e2b1-9a3c-4b2e-9b6e-7e2a9c3f1a2b",
    "status": "success",
    "file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.txt",
    "preview": "U29tZUJhc2U2NFByZXZpZXc="
  }
}

If the job is still processing:

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "queued",
  "message": "Your job is being processed.",
  "retry_after": 2
}

If the job failed:

{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "failed",
  "error": {
    "code": "INVALID_CSV",
    "message": "Failed to parse CSV input.",
    "details": {"message": "Error parsing CSV"}
  }
}


Notes for Developers

  • The API supports three input modes: body, url, and file.
  • For url or file mode, the request is processed asynchronously and returns a job_id.
  • Use the Status API to poll job progress or retrieve results.
  • The output file is stored securely and accessible via a signed download URL.
  • The preview field in responses contains the first 100 KB of the Base64 output for quick inspection.