CSV Whitespace Trim API¶
Overview¶
The CSV Whitespace Trim API removes leading and trailing whitespace from all CSV headers and cell values.
It supports automatic delimiter detection or a custom delimiter via headers.
The API can process CSV content directly (Body Mode) or asynchronously from a remote file or uploaded file (URL/File Mode).
Output is a cleaned CSV file hosted temporarily for download.
Endpoint (POST)¶
POST https://api.apidatatools.com/csv-whitespace-trim-api
Headers¶
| Header | Type | Description |
|---|---|---|
x-api-key | string | Your API key for authentication |
x-source-type | string | Input mode: body, url, or file |
x-delimiter | string | Optional custom delimiter (e.g., ,, ;, |) |
x-has-header | string | Optional flag (true/false) indicating if CSV has a header row |
Accepted File Extensions¶
This tool accepts the following file types when using URL or File mode:
.txt, .csv, .log
Input Example (Body Mode)¶
Name , Age , City
Alice , 30 , New York
Bob , 25 , Los Angeles
Input Example (URL Mode)¶
{
"url": "https://example.com/data.csv"
}
Input Example (File Mode)¶
{
"file": "user_uploads/abc123/data.csv"
}
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/csv-whitespace-trim-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: body" \
-H "Content-Type: text/plain" \
-d 'name,age,department
Alice,30,Engineering
Bob,25,Marketing'
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/csv-whitespace-trim-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: url" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/data.csv"}'
Asynchronous (Input File)¶
curl -X POST "https://api.apidatatools.com/csv-whitespace-trim-api" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-source-type: file" \
-H "Content-Type: application/json" \
-d '{"file": "user_uploads/abc123/data.csv"}'
Example Response¶
Successful (Body Mode)¶
{
"status": "success",
"request_id": "req-12345",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.csv",
"preview": "Name,Age,City\nAlice,30,New York\nBob,25,Los Angeles\n"
}
Async Job Accepted¶
{
"status": "accepted",
"job_id": "job-67890",
"status_url": "https://api.apidatatools.com/jobs/job-67890",
"request_id": "req-12345"
}
Error Handling¶
| Error Code | HTTP Status | Description | Example |
|---|---|---|---|
INVALID_CSV | 400 | CSV content is empty or cannot be parsed | {"status":"error","error":"INVALID_CSV","details":{"message":"Empty CSV input."}} |
CSV_TRIM_FAILED | 400 | Failed to trim whitespace from CSV cells | {"status":"error","error":"CSV_TRIM_FAILED","details":{"message":"Failed to trim CSV cell whitespace."}} |
INVALID_BODY_ENCODING | 400 | 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 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."}} |
INVALID_URL | 400 | Invalid or missing URL in async mode | {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}} |
URL_UNREACHABLE | 400 | URL cannot be reached | {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL."}} |
URL_NOT_OK | 400 | URL 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 | Unsupported file extension | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension."}} |
FILE_UNAVAILABLE | 400 | File not accessible in S3 | {"status":"error","error":"FILE_UNAVAILABLE","details":{"message":"Could not access file."}} |
INVALID_SOURCE_TYPE | 400 | Invalid x-source-type header | {"status":"error","error":"INVALID_SOURCE_TYPE","details":{"message":"Must be 'url' or 'file'."}} |
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 following endpoint:
GET https://api.apidatatools.com/jobs/{job_id}
Example Status Response for Async¶
Queued¶
{
"job_id": "job-67890",
"status": "queued",
"message": "Your job is being processed.",
"retry_after": 2
}
Success¶
{
"job_id": "job-67890",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345689,
"result": {
"status": "success",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abc123.csv",
"preview": "Name,Age,City\nAlice,30,New York\nBob,25,Los Angeles\n"
}
}
Failed¶
{
"job_id": "job-67890",
"status": "failed",
"error": {
"code": "INVALID_CSV",
"message": "Failed to parse CSV.",
"details": {"message": "Error tokenizing data"}
}
}
Notes for Developers¶
- The tool automatically detects CSV delimiters unless
x-delimiteris provided. - If
x-has-headeris set tofalse, columns are auto-named (column_1,column_2, ...). - The output file is stored temporarily and accessible via the returned download URL.
- For large files or remote sources, use
x-source-type: urlorx-source-type: fileto create an async job. - Async jobs can be tracked using the
/jobs/{job_id}status endpoint. - Every response includes a unique
request_idfor traceability. - Ensure file extensions match accepted types when using URL or File mode.