API Integration
UnDatasIO provides comprehensive APIs and SDKs to integrate file processing and data transformation capabilities into your applications. Our RESTful API and client libraries support multiple programming languages and platforms.
RESTful API
Section titled “RESTful API”Base URL
Section titled “Base URL”https://api.undatasio.com/v1Authentication
Section titled “Authentication”All API requests require authentication using API keys:
# Include in headersAuthorization: Bearer YOUR_API_KEY
# Or as query parameter?api_key=YOUR_API_KEYRate Limits
Section titled “Rate Limits”- Free Tier: 1,000 requests per hour
- Pro Tier: 10,000 requests per hour
- Enterprise: Custom limits
Core Endpoints
Section titled “Core Endpoints”File Upload
Section titled “File Upload”Upload files for processing:
POST /files/uploadContent-Type: multipart/form-data
# Form datafile: [binary file data]options: { "autoDetect": true, "validateSchema": true}Response:
{ "fileId": "f_1234567890", "filename": "data.csv", "size": 1024, "status": "uploaded", "uploadedAt": "2024-01-15T10:30:00Z"}File Parsing
Section titled “File Parsing”Parse uploaded files:
POST /files/{fileId}/parseContent-Type: application/json
{ "format": "csv", "options": { "delimiter": "comma", "hasHeader": true, "encoding": "UTF-8" }}Response:
{ "parseId": "p_1234567890", "status": "completed", "result": { "rows": 1000, "columns": 5, "preview": [...], "schema": {...} }, "completedAt": "2024-01-15T10:31:00Z"}Data Processing
Section titled “Data Processing”Process parsed data:
POST /data/{parseId}/processContent-Type: application/json
{ "operations": [ { "type": "filter", "condition": { "column": "age", "operator": ">=", "value": 18 } }, { "type": "transform", "column": "name", "operation": "uppercase" } ]}Data Export
Section titled “Data Export”Export processed data:
GET /data/{processId}/export?format=csv&includeHeader=trueSDK Libraries
Section titled “SDK Libraries”JavaScript/Node.js
Section titled “JavaScript/Node.js”Install the SDK:
npm install @undatasio/sdkBasic Usage:
import { UnDatasIO } from "@undatasio/sdk";
const client = new UnDatasIO({ apiKey: "your_api_key_here", baseUrl: "https://api.undatasio.com/v1",});
// Upload and parse a fileconst file = await client.uploadFile("data.csv", { autoDetect: true, validateSchema: true,});
const parsed = await client.parseFile(file.fileId, { format: "csv", delimiter: "comma", hasHeader: true,});
// Process the dataconst processed = await client.processData(parsed.parseId, { operations: [ { type: "filter", condition: { column: "age", operator: ">=", value: 18 }, }, ],});
// Export resultsconst csvData = await client.exportData(processed.processId, { format: "csv", includeHeader: true,});Advanced Features:
// Batch processingconst results = await client.batchProcess( ["file1.csv", "file2.json", "file3.xlsx"], { operations: [ { type: "clean", strategy: "remove_duplicates" }, { type: "validate", schema: userSchema }, ], });
// Streaming uploadconst stream = client.createUploadStream("large-file.csv");stream.on("progress", (progress) => { console.log(`Upload progress: ${progress}%`);});
// Real-time processingconst processor = client.createRealTimeProcessor({ onData: (data) => { console.log("Processed data:", data); }, onError: (error) => { console.error("Processing error:", error); },});Python
Section titled “Python”Install the SDK:
pip install undatasio-sdkBasic Usage:
from undatasio import UnDatasIO
client = UnDatasIO(api_key='your_api_key_here')
# Upload and parse a filewith open('data.csv', 'rb') as file: result = client.upload_file( file=file, options={ 'auto_detect': True, 'validate_schema': True } )
parsed = client.parse_file( file_id=result['fileId'], options={ 'format': 'csv', 'delimiter': 'comma', 'has_header': True })
# Process the dataprocessed = client.process_data( parse_id=parsed['parseId'], operations=[ { 'type': 'filter', 'condition': { 'column': 'age', 'operator': '>=', 'value': 18 } } ])
# Export resultscsv_data = client.export_data( process_id=processed['processId'], format='csv', include_header=True)Advanced Features:
# Async processingimport asynciofrom undatasio import AsyncUnDatasIO
async def process_files(): client = AsyncUnDatasIO(api_key='your_api_key_here')
tasks = [] for filename in ['file1.csv', 'file2.json']: task = client.upload_and_process(filename) tasks.append(task)
results = await asyncio.gather(*tasks) return results
# Data pipelinepipeline = client.create_pipeline([ {'type': 'upload', 'file': 'data.csv'}, {'type': 'parse', 'format': 'csv'}, {'type': 'clean', 'strategy': 'remove_duplicates'}, {'type': 'transform', 'operations': [...]}, {'type': 'export', 'format': 'json'}])
result = await pipeline.execute()Add to your pom.xml:
<dependency> <groupId>com.undatasio</groupId> <artifactId>undatasio-sdk</artifactId> <version>1.0.0</version></dependency>Basic Usage:
import com.undatasio.UnDatasIO;import com.undatasio.models.*;
UnDatasIO client = new UnDatasIO("your_api_key_here");
// Upload and parse a fileFileUploadRequest uploadRequest = FileUploadRequest.builder() .file(new File("data.csv")) .autoDetect(true) .validateSchema(true) .build();
FileUploadResponse uploadResponse = client.uploadFile(uploadRequest);
// Parse the fileParseRequest parseRequest = ParseRequest.builder() .fileId(uploadResponse.getFileId()) .format("csv") .delimiter("comma") .hasHeader(true) .build();
ParseResponse parseResponse = client.parseFile(parseRequest);
// Process the dataList<Operation> operations = Arrays.asList( Operation.builder() .type("filter") .condition(Condition.builder() .column("age") .operator(">=") .value(18) .build()) .build());
ProcessRequest processRequest = ProcessRequest.builder() .parseId(parseResponse.getParseId()) .operations(operations) .build();
ProcessResponse processResponse = client.processData(processRequest);
// Export resultsExportRequest exportRequest = ExportRequest.builder() .processId(processResponse.getProcessId()) .format("csv") .includeHeader(true) .build();
byte[] csvData = client.exportData(exportRequest);Install the SDK:
go get github.com/undatasio/go-sdkBasic Usage:
package main
import ( "fmt" "log" "github.com/undatasio/go-sdk")
func main() { client := undatasio.NewClient("your_api_key_here")
// Upload and parse a file file, err := os.Open("data.csv") if err != nil { log.Fatal(err) } defer file.Close()
uploadResp, err := client.UploadFile(&undatasio.UploadRequest{ File: file, AutoDetect: true, ValidateSchema: true, }) if err != nil { log.Fatal(err) }
// Parse the file parseResp, err := client.ParseFile(&undatasio.ParseRequest{ FileID: uploadResp.FileID, Format: "csv", Delimiter: "comma", HasHeader: true, }) if err != nil { log.Fatal(err) }
// Process the data processResp, err := client.ProcessData(&undatasio.ProcessRequest{ ParseID: parseResp.ParseID, Operations: []undatasio.Operation{ { Type: "filter", Condition: undatasio.Condition{ Column: "age", Operator: ">=", Value: 18, }, }, }, }) if err != nil { log.Fatal(err) }
// Export results csvData, err := client.ExportData(&undatasio.ExportRequest{ ProcessID: processResp.ProcessID, Format: "csv", IncludeHeader: true, }) if err != nil { log.Fatal(err) }
fmt.Printf("Exported data: %s\n", string(csvData))}Webhooks
Section titled “Webhooks”Set up webhooks for real-time notifications:
POST /webhooksContent-Type: application/json
{ "url": "https://your-app.com/webhook", "events": ["file.uploaded", "file.parsed", "data.processed"], "secret": "your_webhook_secret"}Webhook Payload:
{ "event": "file.parsed", "timestamp": "2024-01-15T10:31:00Z", "data": { "fileId": "f_1234567890", "parseId": "p_1234567890", "status": "completed", "result": { "rows": 1000, "columns": 5 } }, "signature": "sha256=..."}Error Handling
Section titled “Error Handling”HTTP Status Codes
Section titled “HTTP Status Codes”- 200: Success
- 400: Bad Request (invalid parameters)
- 401: Unauthorized (invalid API key)
- 403: Forbidden (insufficient permissions)
- 404: Not Found (resource doesn’t exist)
- 429: Too Many Requests (rate limit exceeded)
- 500: Internal Server Error
Error Response Format
Section titled “Error Response Format”{ "error": { "code": "INVALID_FILE_FORMAT", "message": "Unsupported file format", "details": { "fileType": "unknown", "supportedFormats": ["csv", "json", "xlsx"] } }}SDK Error Handling
Section titled “SDK Error Handling”try { const result = await client.uploadFile("invalid.txt");} catch (error) { if (error.code === "INVALID_FILE_FORMAT") { console.log("File format not supported"); } else if (error.code === "RATE_LIMIT_EXCEEDED") { console.log("Rate limit exceeded, retry later"); } else { console.log("Unexpected error:", error.message); }}Best Practices
Section titled “Best Practices”API Usage
Section titled “API Usage”- Use HTTPS: Always use HTTPS for API requests
- Handle Rate Limits: Implement exponential backoff for retries
- Validate Inputs: Validate file formats and parameters
- Monitor Usage: Track API usage and costs
- Error Handling: Implement comprehensive error handling
Performance Optimization
Section titled “Performance Optimization”- Batch Operations: Use batch endpoints for multiple files
- Streaming: Use streaming for large files
- Caching: Cache results when appropriate
- Async Processing: Use async operations for better performance
Security
Section titled “Security”- Secure API Keys: Store API keys securely
- Webhook Validation: Validate webhook signatures
- Input Sanitization: Sanitize all inputs
- HTTPS Only: Use HTTPS for all communications
SDK Examples
Section titled “SDK Examples”File Processing Pipeline
Section titled “File Processing Pipeline”// Complete file processing pipelineasync function processFile(filename, operations) { const client = new UnDatasIO({ apiKey: "your_api_key" });
try { // Upload file const upload = await client.uploadFile(filename); console.log("File uploaded:", upload.fileId);
// Parse file const parsed = await client.parseFile(upload.fileId); console.log("File parsed:", parsed.parseId);
// Process data const processed = await client.processData(parsed.parseId, operations); console.log("Data processed:", processed.processId);
// Export results const exported = await client.exportData(processed.processId, { format: "csv", includeHeader: true, });
return exported; } catch (error) { console.error("Processing failed:", error); throw error; }}
// Usageconst operations = [ { type: "filter", condition: { column: "age", operator: ">=", value: 18 } }, { type: "transform", column: "name", operation: "uppercase" },];
processFile("users.csv", operations) .then((result) => console.log("Processing complete")) .catch((error) => console.error("Error:", error));Real-time Processing
Section titled “Real-time Processing”// Real-time file processing with webhooksconst client = new UnDatasIO({ apiKey: "your_api_key" });
// Set up webhook handlerapp.post("/webhook", (req, res) => { const { event, data } = req.body;
switch (event) { case "file.parsed": // Start processing when file is parsed client .processData(data.parseId, operations) .then((result) => console.log("Processing started:", result.processId)); break;
case "data.processed": // Export when processing is complete client .exportData(data.processId, { format: "json" }) .then((result) => console.log("Export complete")); break; }
res.status(200).send("OK");});Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Authentication Errors:
- Verify API key is correct
- Check API key permissions
- Ensure API key is not expired
File Upload Issues:
- Check file size limits
- Verify supported file formats
- Ensure proper file encoding
Processing Errors:
- Validate operation parameters
- Check data schema compatibility
- Review error messages for details