Back to API Reference

Data Files API

Base URL: /api/data

Overview

The Data Files API allows you to upload, store, and manage data files (primarily CSV format) that can be used for document generation and email campaigns. All endpoints require JWT authentication.

Authentication

All endpoints require authentication:

Authorization: Bearer 

---

Endpoints

POST /api/data

Save/upload a new data file.

Request:

{

"fileName": "customers.csv",

"fileType": "csv",

"fileContent": "Name,Email,Company\\nJohn Doe,john@example.com,Acme Corp\\nJane Smith,jane@example.com,Tech Inc"

}

Required Fields:

Success Response (201):

{

"success": true,

"file": {

"Id": "uuid-of-new-file",

"UserId": "uuid-of-user",

"FileName": "customers.csv",

"FileType": "csv",

"CreatedAt": "2026-02-12T10:30:00Z",

"UpdatedAt": "2026-02-12T10:30:00Z"

},

"message": "Data file saved successfully"

}

Error Responses:

400 - Missing Fields:

{

"message": "Missing required fields: fileName, fileType, fileContent"

}

401 - Unauthorized:

{

"message": "User not authenticated"

}

---

GET /api/data

Retrieve all data files for the authenticated user.

Success Response (200):

{

"success": true,

"files": [

{

"Id": "uuid-1",

"FileName": "customers.csv",

"FileType": "csv",

"CreatedAt": "2026-02-12T10:30:00Z",

"UpdatedAt": "2026-02-12T10:30:00Z"

},

{

"Id": "uuid-2",

"FileName": "products.csv",

"FileType": "csv",

"CreatedAt": "2026-02-11T09:15:00Z",

"UpdatedAt": "2026-02-11T09:15:00Z"

}

],

"count": 2

}

Note: File content is NOT included in list responses for performance.

---

GET /api/data/:id

Retrieve a specific data file by ID, including full content.

URL Parameters:

Success Response (200):

{

"success": true,

"file": {

"Id": "uuid-1",

"UserId": "user-uuid",

"FileName": "customers.csv",

"FileType": "csv",

"FileContent": "Name,Email,Company\\nJohn Doe,john@example.com,Acme Corp\\nJane Smith,jane@example.com,Tech Inc",

"CreatedAt": "2026-02-12T10:30:00Z",

"UpdatedAt": "2026-02-12T10:30:00Z"

}

}

Error Responses:

404 - Not Found:

{

"message": "Data file not found"

}

403 - Forbidden (file belongs to different user):

{

"message": "Access denied"

}

---

PUT /api/data/:id

Update an existing data file.

URL Parameters:

Request:

{

"fileName": "customers_updated.csv",

"fileType": "csv",

"fileContent": "Name,Email,Company,Phone\\nJohn Doe,john@example.com,Acme Corp,555-0100"

}

Success Response (200):

{

"success": true,

"file": {

"Id": "uuid-1",

"FileName": "customers_updated.csv",

"FileType": "csv",

"UpdatedAt": "2026-02-12T11:45:00Z"

},

"message": "Data file updated successfully"

}

Error Responses:

404 - Not Found:

{

"message": "Data file not found"

}

403 - Forbidden:

{

"message": "Access denied"

}

---

DELETE /api/data/:id

Delete a data file.

URL Parameters:

Success Response (200):

{

"success": true,

"message": "Data file deleted successfully"

}

Error Responses:

404 - Not Found:

{

"message": "Data file not found"

}

403 - Forbidden:

{

"message": "Access denied"

}

---

CSV Route Extensions

The Data Files API is complemented by CSV-specific operations at /api/csv:

POST /api/csv/upload

Upload CSV via multipart/form-data (for large files).

Form Data:

Response:

{

"success": true,

"fileId": "uuid",

"fileName": "customers.csv",

"rowCount": 150

}

---

Data File Usage

Data files can be used in:

---

Storage Limits

---

Best Practices

CSV Format

Name,Email,Company,Title

John Doe,john@example.com,Acme Corp,CEO

Jane Smith,jane@example.com,Tech Inc,CTO

Bob Johnson,bob@example.com,StartUp LLC,Developer

Tips:

  • Use headers in first row
  • Consistent column count
  • Escape commas in values: "Company, Inc"
  • UTF-8 encoding
  • Windows/Unix line endings supported
  • File Naming

    Performance

    ---

    Example: Complete Workflow

    // 1. Upload data file
    

    const uploadResponse = await fetch('http://localhost:3001/api/data', {

    method: 'POST',

    headers: {

    'Authorization': 'Bearer ' + token,

    'Content-Type': 'application/json'

    },

    body: JSON.stringify({

    fileName: 'customers.csv',

    fileType: 'csv',

    fileContent: 'Name,Email\\nJohn,john@example.com\\nJane,jane@example.com'

    })

    });

    const { file } = await uploadResponse.json();

    console.log('File ID:', file.Id);

    // 2. Retrieve file list

    const listResponse = await fetch('http://localhost:3001/api/data', {

    headers: {

    'Authorization': 'Bearer ' + token

    }

    });

    const { files } = await listResponse.json();

    console.log('Total files:', files.length);

    // 3. Get specific file with content

    const detailResponse = await fetch(http://localhost:3001/api/data/${file.Id}, {

    headers: {

    'Authorization': 'Bearer ' + token

    }

    });

    const { file: fullFile } = await detailResponse.json();

    console.log('File content:', fullFile.FileContent);

    // 4. Update file

    await fetch(http://localhost:3001/api/data/${file.Id}, {

    method: 'PUT',

    headers: {

    'Authorization': 'Bearer ' + token,

    'Content-Type': 'application/json'

    },

    body: JSON.stringify({

    fileName: 'customers_updated.csv',

    fileType: 'csv',

    fileContent: 'Name,Email,Phone\\nJohn,john@example.com,555-0100'

    })

    });

    // 5. Delete file

    await fetch(http://localhost:3001/api/data/${file.Id}, {

    method: 'DELETE',

    headers: {

    'Authorization': 'Bearer ' + token

    }

    });

    ---

    Related APIs