Spaces:
Runtime error
Runtime error
|
Download docs/API_DOCUMENTATION.md from CleanflowAI/cleanflowai: direct link, hf CLI and curl.
- Browser
- Download file 12.5 kB
-
https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/379bfdec22d853a62857ff42ff6fbab50e65c8a8/docs/API_DOCUMENTATION.md
- Command line
-
hf download hf://spaces/CleanflowAI/cleanflowai@379bfdec22d853a62857ff42ff6fbab50e65c8a8/docs/API_DOCUMENTATION.md
-
curl -L -o API_DOCUMENTATION.md https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/379bfdec22d853a62857ff42ff6fbab50e65c8a8/docs/API_DOCUMENTATION.md
12.5 kB
| # ERP to CDF Transformation API Documentation | |
| ## Overview | |
| The ERP to CDF Transformation API v2.0 provides high-performance data transformation capabilities using Polars and DuckDB. It converts data from various ERP systems into a standardized Common Data Frame (CDF) format. | |
| **Base URL**: `http://localhost:8000` | |
| **API Version**: 2.0.0 | |
| **Engine**: Polars + DuckDB | |
| ## Features | |
| - ✅ **11 ERP Systems**: Oracle Fusion, SAP ERP, Microsoft Dynamics, NetSuite, Workday, Infor M3/LN, Epicor Kinetic, QAD ERP, IFS Cloud, Sage Intacct | |
| - ✅ **5 Entity Types**: Sales Orders, Customers, Invoices, Purchase Orders, Inventory Items | |
| - ✅ **Multiple File Formats**: CSV, Excel, JSON, SQL, Parquet | |
| - ✅ **Auto-Detection**: Intelligent ERP system and entity type recognition | |
| - ✅ **Data Format Consistency**: ISO dates, DECIMAL(18,2) precision, proper boolean/text handling | |
| - ✅ **High Performance**: Lightning-fast processing with Polars + DuckDB | |
| ## Authentication | |
| Currently, the API does not require authentication. For production deployments, implement appropriate authentication mechanisms. | |
| ## Interactive Documentation | |
| - **Swagger UI**: `http://localhost:8000/docs` | |
| - **ReDoc**: `http://localhost:8000/redoc` | |
| ## Endpoints | |
| ### Health & Information | |
| #### GET /health | |
| Check API health status. | |
| **Response:** | |
| ```json | |
| { | |
| "status": "healthy", | |
| "version": "2.0.0", | |
| "engine": "Polars + DuckDB" | |
| } | |
| ``` | |
| #### GET /entities | |
| Get list of supported entity types. | |
| **Response:** | |
| ```json | |
| [ | |
| "sales_orders", | |
| "customers", | |
| "invoices", | |
| "purchase_orders", | |
| "inventory_items" | |
| ] | |
| ``` | |
| #### GET /erps | |
| Get list of supported ERP systems. | |
| **Response:** | |
| ```json | |
| [ | |
| "Oracle Fusion", | |
| "SAP ERP", | |
| "Microsoft Dynamics", | |
| "NetSuite", | |
| "Workday", | |
| "Infor M3", | |
| "Infor LN", | |
| "Epicor Kinetic", | |
| "QAD ERP", | |
| "IFS Cloud", | |
| "Sage Intacct" | |
| ] | |
| ``` | |
| #### GET /formats | |
| Get list of supported file formats. | |
| **Response:** | |
| ```json | |
| [ | |
| "csv", | |
| "excel", | |
| "json", | |
| "sql", | |
| "parquet" | |
| ] | |
| ``` | |
| ### Core Transformation | |
| #### POST /transform | |
| Transform JSON data to CDF format. | |
| **Request Body:** | |
| ```json | |
| { | |
| "auto_select_erp": true, | |
| "auto_select_entity": true, | |
| "entity": "sales_orders", | |
| "erp": "NetSuite", | |
| "data": [ | |
| { | |
| "tranId": "SO1001", | |
| "trandate": "2025-08-04", | |
| "entity": "CUST01", | |
| "total": 1249.0 | |
| } | |
| ] | |
| } | |
| ``` | |
| **Response:** | |
| ```json | |
| { | |
| "success": true, | |
| "data": [ | |
| { | |
| "order_id": "SO1001", | |
| "order_date": "2025-08-04", | |
| "customer_id": "CUST01", | |
| "total_amount": 1249.0, | |
| "status": null, | |
| "currency": null, | |
| "notes": null, | |
| "item_id": null, | |
| "description": null, | |
| "quantity": null, | |
| "unit_price": null, | |
| "line_total": null, | |
| "tax_code": null | |
| } | |
| ], | |
| "detected_erp": "NetSuite", | |
| "detected_entity": "sales_orders", | |
| "transformation_mode": "template", | |
| "confidence_score": 1.0, | |
| "message": "Successfully transformed using template mapping", | |
| "column_mappings": { | |
| "tranId": "order_id", | |
| "trandate": "order_date", | |
| "entity": "customer_id", | |
| "total": "total_amount" | |
| }, | |
| "row_count": 1, | |
| "processing_time_ms": 45.2 | |
| } | |
| ``` | |
| #### POST /transform/file | |
| Transform uploaded file to CDF format. | |
| **Parameters:** | |
| - `file` (form-data): File to transform | |
| - `auto_select_erp` (form-data): Auto-detect ERP system (default: true) | |
| - `auto_select_entity` (form-data): Auto-detect entity type (default: true) | |
| - `entity` (form-data): Entity type if known | |
| - `erp` (form-data): ERP system if known | |
| - `output_format` (form-data): Output format (default: json) | |
| **Response:** Same as `/transform` endpoint | |
| **cURL Example:** | |
| ```bash | |
| curl -X POST "http://localhost:8000/transform/file" \ | |
| -F "file=@sample.csv" \ | |
| -F "auto_select_erp=true" \ | |
| -F "auto_select_entity=true" | |
| ``` | |
| #### POST /transform/file/download | |
| Transform uploaded file and return as downloadable file. | |
| **Parameters:** Same as `/transform/file` | |
| **Response:** File download with transformed data | |
| **cURL Example:** | |
| ```bash | |
| curl -X POST "http://localhost:8000/transform/file/download" \ | |
| -F "file=@sample.csv" \ | |
| -F "output_format=csv" \ | |
| -o transformed_data.csv | |
| ``` | |
| ### Analysis & Validation | |
| #### POST /analyze | |
| Analyze uploaded file and provide insights. | |
| **Parameters:** | |
| - `file` (form-data): File to analyze | |
| **Response:** | |
| ```json | |
| { | |
| "column_info": { | |
| "column_count": 4, | |
| "row_count": 100, | |
| "columns": ["tranId", "trandate", "entity", "total"], | |
| "dtypes": { | |
| "tranId": "String", | |
| "trandate": "String", | |
| "entity": "String", | |
| "total": "Float64" | |
| }, | |
| "null_counts": { | |
| "tranId": 0, | |
| "trandate": 0, | |
| "entity": 0, | |
| "total": 2 | |
| }, | |
| "sample_data": { | |
| "tranId": ["SO1001", "SO1002", "SO1003"], | |
| "trandate": ["2025-08-04", "2025-08-04", "2025-08-05"], | |
| "entity": ["CUST01", "CUST02", "CUST01"], | |
| "total": [1249.0, 850.5, 2100.0] | |
| } | |
| }, | |
| "erp_entity_suggestions": [ | |
| { | |
| "entity": "sales_orders", | |
| "erp": "NetSuite", | |
| "confidence": 0.85, | |
| "above_threshold": true | |
| }, | |
| { | |
| "entity": "sales_orders", | |
| "erp": "Oracle Fusion", | |
| "confidence": 0.65, | |
| "above_threshold": true | |
| } | |
| ], | |
| "available_entities": ["sales_orders", "customers", "invoices", "purchase_orders", "inventory_items"], | |
| "available_erps": ["Oracle Fusion", "SAP ERP", "Microsoft Dynamics", "NetSuite", "Workday", "Infor M3", "Infor LN", "Epicor Kinetic", "QAD ERP", "IFS Cloud", "Sage Intacct"], | |
| "processing_time_ms": 23.1 | |
| } | |
| ``` | |
| #### POST /validate | |
| Validate file structure and content. | |
| **Parameters:** | |
| - `file` (form-data): File to validate | |
| **Response:** | |
| ```json | |
| { | |
| "valid": true, | |
| "file_format": "csv", | |
| "column_info": { | |
| "column_count": 4, | |
| "row_count": 100, | |
| "columns": ["tranId", "trandate", "entity", "total"], | |
| "dtypes": { | |
| "tranId": "String", | |
| "trandate": "String", | |
| "entity": "String", | |
| "total": "Float64" | |
| }, | |
| "null_counts": { | |
| "tranId": 0, | |
| "trandate": 0, | |
| "entity": 0, | |
| "total": 2 | |
| } | |
| }, | |
| "message": "File is valid and can be processed" | |
| } | |
| ``` | |
| ### Template Information | |
| #### GET /template/erp/{erp}/entity/{entity} | |
| Get template mapping for specific ERP and entity. | |
| **Parameters:** | |
| - `erp`: ERP system name | |
| - `entity`: Entity type | |
| **Example:** `GET /template/erp/NetSuite/entity/sales_orders` | |
| **Response:** | |
| ```json | |
| { | |
| "erp": "NetSuite", | |
| "entity": "sales_orders", | |
| "mapping": { | |
| "tranId": "order_id", | |
| "trandate": "order_date", | |
| "entity": "customer_id", | |
| "total": "total_amount", | |
| "status": "status", | |
| "currency": "currency", | |
| "memo": "notes" | |
| }, | |
| "cdf_schema": [ | |
| "order_id", | |
| "order_date", | |
| "customer_id", | |
| "status", | |
| "currency", | |
| "total_amount", | |
| "notes", | |
| "item_id", | |
| "description", | |
| "quantity", | |
| "unit_price", | |
| "line_total", | |
| "tax_code" | |
| ] | |
| } | |
| ``` | |
| #### GET /template/entity/{entity}/schema | |
| Get CDF schema for specific entity. | |
| **Parameters:** | |
| - `entity`: Entity type | |
| **Example:** `GET /template/entity/customers/schema` | |
| **Response:** | |
| ```json | |
| { | |
| "entity": "customers", | |
| "cdf_schema": [ | |
| "customer_id", | |
| "customer_name", | |
| "contact_email", | |
| "phone_number", | |
| "alt_phone", | |
| "is_company", | |
| "status", | |
| "currency", | |
| "created_date", | |
| "last_modified", | |
| "address_type", | |
| "address_line1", | |
| "city", | |
| "state", | |
| "postal_code", | |
| "country" | |
| ], | |
| "field_count": 16 | |
| } | |
| ``` | |
| ## Data Models | |
| ### Entity Types | |
| | Entity | Description | CDF Fields | | |
| |--------|-------------|------------| | |
| | `sales_orders` | Sales transactions with line items | 13 fields | | |
| | `customers` | Customer master data with full address support | 16 fields | | |
| | `invoices` | Invoice documents | 14 fields | | |
| | `purchase_orders` | Purchase orders | 14 fields | | |
| | `inventory_items` | Product catalog | 12 fields | | |
| ### CDF Schema Details | |
| #### Sales Orders (13 fields) | |
| - `order_id`, `order_date`, `customer_id`, `status`, `currency` | |
| - `total_amount`, `notes`, `item_id`, `description`, `quantity` | |
| - `unit_price`, `line_total`, `tax_code` | |
| #### Customers (16 fields) | |
| - **Core**: `customer_id`, `customer_name`, `contact_email`, `phone_number`, `alt_phone` | |
| - **Business**: `is_company`, `status`, `currency`, `created_date`, `last_modified` | |
| - **Address**: `address_type`, `address_line1`, `city`, `state`, `postal_code`, `country` | |
| #### Invoices (14 fields) | |
| - `invoice_id`, `invoice_date`, `customer_id`, `status`, `currency` | |
| - `total_amount`, `due_date`, `notes`, `item_id`, `description` | |
| - `quantity`, `unit_price`, `line_total`, `tax_code` | |
| #### Purchase Orders (14 fields) | |
| - `po_id`, `po_date`, `vendor_id`, `status`, `currency` | |
| - `total_amount`, `expected_receipt_date`, `notes`, `item_id`, `description` | |
| - `quantity`, `unit_price`, `line_total`, `tax_code` | |
| #### Inventory Items (12 fields) | |
| - `item_id`, `item_name`, `description`, `purchase_description`, `sales_description` | |
| - `base_price`, `cost_price`, `unit_type`, `is_active`, `quantity_on_hand` | |
| - `reorder_point`, `preferred_vendor_id` | |
| ## Data Format Consistency | |
| ### Date Fields | |
| - **APIs/Database**: ISO `yyyy-MM-dd` format | |
| - **Human-readable files**: `dd-MMMM-yyyy` format (e.g., `04-August-2025`) | |
| ### Decimal Fields | |
| - **Precision**: DECIMAL(18,2) for all currency and pricing fields | |
| - **Format**: Always 2 decimal places (e.g., `1249.00`) | |
| ### Boolean Fields | |
| - **JSON/API**: `true`/`false` | |
| - **Database**: `1`/`0` | |
| ### Text Fields | |
| - **Encoding**: UTF-8 with proper CSV/JSON escaping | |
| - **Processing**: Trimmed and normalized | |
| ## Error Handling | |
| ### HTTP Status Codes | |
| | Code | Description | | |
| |------|-------------| | |
| | 200 | Success | | |
| | 400 | Bad Request (invalid input, unsupported format) | | |
| | 404 | Not Found (template mapping not found) | | |
| | 422 | Validation Error (invalid request body) | | |
| | 500 | Internal Server Error | | |
| ### Error Response Format | |
| ```json | |
| { | |
| "detail": "Error message describing what went wrong" | |
| } | |
| ``` | |
| ### Common Errors | |
| #### 400 Bad Request | |
| ```json | |
| { | |
| "detail": "Unsupported file format: .txt" | |
| } | |
| ``` | |
| #### 404 Not Found | |
| ```json | |
| { | |
| "detail": "No mapping found for CustomERP -> sales_orders" | |
| } | |
| ``` | |
| #### 422 Validation Error | |
| ```json | |
| { | |
| "detail": [ | |
| { | |
| "loc": ["body", "entity"], | |
| "msg": "field required", | |
| "type": "value_error.missing" | |
| } | |
| ] | |
| } | |
| ``` | |
| ## Rate Limiting | |
| Currently, no rate limiting is implemented. For production deployments, consider implementing rate limiting based on your requirements. | |
| ## Performance | |
| ### Benchmarks | |
| - **Small files** (< 1MB): < 100ms processing time | |
| - **Medium files** (1-10MB): < 500ms processing time | |
| - **Large files** (10-100MB): < 2s processing time | |
| ### Optimization Tips | |
| 1. Use Parquet format for large datasets | |
| 2. Enable auto-detection for unknown data sources | |
| 3. Use the `/analyze` endpoint to understand data structure before transformation | |
| 4. Batch process multiple files using the download endpoint | |
| ## SDK Examples | |
| ### Python | |
| ```python | |
| import requests | |
| # Transform JSON data | |
| response = requests.post('http://localhost:8000/transform', json={ | |
| "auto_select_erp": True, | |
| "auto_select_entity": True, | |
| "data": [{"tranId": "SO1001", "total": 1249.0}] | |
| }) | |
| result = response.json() | |
| print(f"Transformed {result['row_count']} records") | |
| ``` | |
| ### JavaScript | |
| ```javascript | |
| // Transform file upload | |
| const formData = new FormData(); | |
| formData.append('file', fileInput.files[0]); | |
| formData.append('auto_select_erp', 'true'); | |
| fetch('http://localhost:8000/transform/file', { | |
| method: 'POST', | |
| body: formData | |
| }) | |
| .then(response => response.json()) | |
| .then(data => console.log('Success:', data)); | |
| ``` | |
| ### cURL | |
| ```bash | |
| # Analyze file | |
| curl -X POST "http://localhost:8000/analyze" \ | |
| -F "file=@data.csv" | |
| # Transform with specific ERP | |
| curl -X POST "http://localhost:8000/transform/file" \ | |
| -F "file=@data.csv" \ | |
| -F "erp=NetSuite" \ | |
| -F "entity=sales_orders" | |
| ``` | |
| ## Deployment | |
| ### Docker | |
| ```dockerfile | |
| FROM python:3.11-slim | |
| WORKDIR /app | |
| COPY requirements.txt . | |
| RUN pip install -r requirements.txt | |
| COPY . . | |
| EXPOSE 8000 | |
| CMD ["python", "app.py"] | |
| ``` | |
| ### Environment Variables | |
| ```bash | |
| # Optional: OpenAI API key for LLM fallback | |
| OPENAI_API_KEY=your-api-key-here | |
| # Optional: Custom template file path | |
| TEMPLATE_PATH=./custom-template.json | |
| ``` | |
| ## Support | |
| For questions, issues, or feature requests: | |
| 1. Check this documentation | |
| 2. Review the interactive API docs at `/docs` | |
| 3. Search existing issues in the repository | |
| 4. Create a new issue with detailed information | |
| --- | |
| **API Version**: 2.0.0 | |
| **Last Updated**: August 5, 2025 | |
| **Engine**: Polars + DuckDB | |