Data Transformation

Convert between data formats, validate structures, and transform content for different systems.

Quick Reference: All requests go to POST /api/services/execute with your API key in the Authorization: Bearer YOUR_API_KEY header.


Excel/JSON Conversion

Services: excel-to-json, json-to-excel

Convert between Excel spreadsheets and JSON. Perfect for importing data from users or exporting reports they can open in Excel.

Import User-Uploaded Spreadsheet

Process an Excel file uploaded by a user to import their data.

# Python - Parse uploaded Excel file
import requests
import base64

def process_excel_upload(file_bytes):
    file_base64 = base64.b64encode(file_bytes).decode()

    response = requests.post(
        'https://www.acrewity.com/api/services/execute',
        headers={
            'Authorization': 'Bearer YOUR_API_KEY',
            'Content-Type': 'application/json'
        },
        json={
            'service': 'excel-to-json',
            'operation': 'read_excel',
            'parameters': {
                'file': file_base64
            }
        }
    )

    result = response.json()
    sheets = result['result']['data']['sheets']

    # Access each sheet's data
    for sheet_name, sheet_data in sheets.items():
        rows = sheet_data['detectedTable']['asObjects']
        print(f"Sheet: {sheet_name}")
        for row in rows:
            print(f"  {row}")

Export Data as Downloadable Excel (Single Sheet)

Generate an Excel file from your database for users to download.

// JavaScript - Create Excel export
const salesData = [
  { product: 'Widget Pro', quantity: 150, revenue: 4500, region: 'North' },
  { product: 'Widget Basic', quantity: 320, revenue: 3200, region: 'South' },
  { product: 'Widget Pro', quantity: 89, revenue: 2670, region: 'West' }
];

const response = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'json-to-excel',
    operation: 'create_excel',
    parameters: {
      data: salesData,
      sheetName: 'Sales Report Q4'
    }
  })
});

const { result } = await response.json();
// result.data.content is base64-encoded .xlsx file
// result.data.downloadUrl provides a direct download link

With Styling (headerStyle, columnStyles):

// JavaScript - Styled single-sheet Excel
const response = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'json-to-excel',
    operation: 'create_excel',
    parameters: {
      data: salesData,
      sheetName: 'Sales Report Q4',
      headerStyle: {
        bold: true,
        fill: '#4472C4',
        fontColor: '#FFFFFF',
        freeze: true  // Freeze header row
      },
      columnStyles: {
        product: { width: 25 },
        revenue: { numberFormat: '$#,##0', align: 'right', bold: true }
      }
    }
  })
});

Create Multi-Sheet Excel Workbook

Generate an Excel file with multiple worksheets - perfect for comprehensive reports.

Simple Format (arrays of objects):

// JavaScript - Create multi-sheet workbook with arrays
const response = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'json-to-excel',
    operation: 'create_multi_sheet',
    parameters: {
      sheets: {
        'Sales Q4': [
          { product: 'Widget Pro', quantity: 150, revenue: 4500 },
          { product: 'Widget Basic', quantity: 320, revenue: 3200 }
        ],
        'Inventory': [
          { item: 'Widget Pro', stock: 500, warehouse: 'A1' },
          { item: 'Widget Basic', stock: 1200, warehouse: 'B2' }
        ]
      }
    }
  })
});

const { result } = await response.json();
// result.data.downloadUrl provides a direct download link

With detectedTable and range (for precise positioning):

When you need tables to start at specific cells (e.g., below a header or metadata), use the detectedTable format with a range parameter:

// JavaScript - Position tables at specific cells
const response = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'json-to-excel',
    operation: 'create_multi_sheet',
    parameters: {
      sheets: {
        'Report': {
          cells: {
            'A1': { value: 'Monthly Sales Report' },
            'A2': { value: 'Generated: 2024-01-15' }
          },
          detectedTable: {
            headers: ['Product', 'Quantity', 'Revenue'],
            rows: [
              { Product: 'Widget Pro', Quantity: 150, Revenue: 4500 },
              { Product: 'Widget Basic', Quantity: 320, Revenue: 3200 }
            ],
            range: 'A4'  // Table starts at row 4, below the header
          }
        }
      }
    }
  })
});

The range parameter accepts Excel cell references like "A1", "B5", or "C10" to position your table. See JSON to Excel documentation for all supported formats.

Create Professional-Looking Excel with Styling

Add formatting like bold headers, colors, column widths, and freeze panes to create polished Excel exports.

Basic Styled Report:

// JavaScript - Create styled Excel report
const response = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'json-to-excel',
    operation: 'create_multi_sheet',
    parameters: {
      sheets: {
        'Sales Report': {
          detectedTable: {
            headers: ['Product', 'Description', 'Qty', 'Unit Price', 'Total'],
            rows: [
              { Product: 'WP-001', Description: 'Widget Pro with extended features', Qty: 100, 'Unit Price': 29.99, Total: 2999 },
              { Product: 'WB-001', Description: 'Widget Basic', Qty: 250, 'Unit Price': 19.99, Total: 4997.50 }
            ],
            headerStyle: {
              bold: true,
              fill: '#4472C4',
              fontColor: '#FFFFFF',
              freeze: true
            },
            columnStyles: {
              Description: { wrap: true, width: 40 },
              'Unit Price': { numberFormat: '$#,##0.00', align: 'right' },
              Total: { numberFormat: '$#,##0.00', bold: true, align: 'right' }
            }
          }
        }
      }
    }
  })
});

Invoice with Title and Styled Table:

# Python - Create styled invoice
import requests

response = requests.post(
    'https://www.acrewity.com/api/services/execute',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'service': 'json-to-excel',
        'operation': 'create_multi_sheet',
        'parameters': {
            'useCells': True,
            'sheets': {
                'Invoice': {
                    'cells': {
                        'A1': {
                            'value': 'INVOICE',
                            'style': {'bold': True, 'fontSize': 24, 'fill': '#1F4E79', 'fontColor': '#FFFFFF'}
                        },
                        'A2': {'value': 'Invoice #: INV-2024-001', 'style': {'fontSize': 11}},
                        'A3': {'value': 'Date: January 15, 2024', 'style': {'fontSize': 11}},
                        'D1': {'value': 'Acme Corp', 'style': {'bold': True, 'fontSize': 14, 'align': 'right'}},
                        'D2': {'value': '123 Business St', 'style': {'align': 'right'}}
                    },
                    'detectedTable': {
                        'headers': ['Item', 'Description', 'Qty', 'Unit Price', 'Total'],
                        'rows': [
                            {'Item': 'WP-001', 'Description': 'Widget Pro', 'Qty': 10, 'Unit Price': 29.99, 'Total': 299.90},
                            {'Item': 'GB-001', 'Description': 'Gadget Basic', 'Qty': 5, 'Unit Price': 49.99, 'Total': 249.95}
                        ],
                        'range': 'A6',
                        'headerStyle': {
                            'bold': True,
                            'fill': '#4472C4',
                            'fontColor': '#FFFFFF',
                            'align': 'center'
                        },
                        'columnStyles': {
                            'Description': {'wrap': True, 'width': 45},
                            'Unit Price': {'numberFormat': '$#,##0.00', 'align': 'right'},
                            'Total': {'numberFormat': '$#,##0.00', 'bold': True, 'align': 'right'}
                        }
                    },
                    'rowStyles': {
                        '1': {'height': 30}
                    }
                }
            }
        }
    }
)

Style Properties:

See JSON to Excel - Cell Styling for the complete style reference.

Round-Trip: Read Excel, Modify, Write Back

Read an Excel file, modify the data, and save it back - preserving the multi-sheet structure and table positions.

# Python - Round-trip Excel modification
import requests
import base64

# Step 1: Read the original Excel file
with open('original.xlsx', 'rb') as f:
    file_base64 = base64.b64encode(f.read()).decode()

read_response = requests.post(
    'https://www.acrewity.com/api/services/execute',
    headers={'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'},
    json={
        'service': 'excel-to-json',
        'operation': 'read_excel',
        'parameters': {'file': file_base64}
    }
)

sheets_data = read_response.json()['result']['data']['sheets']

# Step 2: Modify the data
# The sheets_data contains detectedTable with headers, rows, and range
for sheet_name, sheet in sheets_data.items():
    if 'detectedTable' in sheet:
        # Modify existing rows
        for row in sheet['detectedTable']['rows']:
            row['processed'] = True  # Add a new column

        # The 'range' property (e.g., "A5") is preserved,
        # so the table will be written at the same position

# Step 3: Write back to Excel - tables stay at original positions
write_response = requests.post(
    'https://www.acrewity.com/api/services/execute',
    headers={'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json'},
    json={
        'service': 'json-to-excel',
        'operation': 'create_multi_sheet',
        'parameters': {'sheets': sheets_data}
    }
)

# Save the modified file
modified_excel = base64.b64decode(write_response.json()['result']['data']['content'])
with open('modified.xlsx', 'wb') as f:
    f.write(modified_excel)

Important: The excel-to-json service returns detectedTable objects with a range property indicating where the table was found. When you pass this back to json-to-excel, the table will be written at that same position, preserving layout.

Preserve Cell Positions and Formulas

For spreadsheets with formulas or specific cell layouts, use useCells to preserve exact cell positions:

// JavaScript - Preserve formulas during round-trip
const fs = require('fs');

// Step 1: Read Excel with cell-level data
const fileBase64 = fs.readFileSync('budget.xlsx').toString('base64');

const readResponse = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'excel-to-json',
    operation: 'read_excel',
    parameters: { file: fileBase64 }
  })
});

const { result } = await readResponse.json();
const sheets = result.data.sheets;

// Step 2: Modify cell values (formulas in cells like B4 will recalculate)
sheets['Budget'].cells['B2'].value = 1800;  // Update rent amount

// Step 3: Write back preserving cell positions and formulas
const writeResponse = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'json-to-excel',
    operation: 'create_multi_sheet',
    parameters: {
      sheets: sheets,
      useCells: true,          // Use exact cell positions
      preserveFormulas: true   // Keep formulas like =SUM(B2:B3)
    }
  })
});

// Formula cells will recalculate when opened in Excel

Use Cases:

Bulk Data Import

Let users upload spreadsheets to bulk-import contacts, products, or other data.

Report Downloads

Offer "Export to Excel" buttons for analytics dashboards and reports.

Data Migration

Convert legacy Excel-based workflows to modern JSON-based systems.

Multi-Sheet Workbooks

Create complex Excel files with multiple sheets for comprehensive reports.


JSON Schema Validation

Service: json-schema-validator

Validate incoming data against JSON schemas. Get detailed error messages when data doesn't match expected structure.

Validate API Webhook Payload

Ensure incoming webhook data matches your expected format before processing.

// JavaScript - Validate webhook payload
const webhookPayload = req.body;

const userSchema = {
  type: 'object',
  properties: {
    event: { type: 'string', enum: ['user.created', 'user.updated', 'user.deleted'] },
    timestamp: { type: 'string', format: 'date-time' },
    data: {
      type: 'object',
      properties: {
        id: { type: 'string', pattern: '^[a-f0-9-]{36}$' },
        email: { type: 'string', format: 'email' },
        name: { type: 'string', minLength: 1, maxLength: 100 }
      },
      required: ['id', 'email']
    }
  },
  required: ['event', 'timestamp', 'data']
};

const response = await fetch('https://www.acrewity.com/api/services/execute', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'json-schema-validator',
    operation: 'validate_json',
    parameters: {
      data: webhookPayload,
      schema: userSchema
    }
  })
});

const { result } = await response.json();
if (!result.data.valid) {
  console.error('Invalid payload:', result.data.errors);
  return res.status(400).json({ error: 'Invalid webhook payload' });
}

Use Cases:

Config File Validation

Validate user-provided configuration files against expected schemas.

Form Data Verification

Validate complex form submissions server-side with detailed error reporting.


Format Conversions

Services: html-to-markdown, markdown-to-html

Convert between HTML and Markdown. Essential for content management systems, email builders, and documentation tools.

Convert Rich Text Editor Content to Markdown

Store user content from a WYSIWYG editor as portable Markdown.

curl -X POST https://www.acrewity.com/api/services/execute \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "service": "html-to-markdown",
    "operation": "convert",
    "parameters": {
      "content": "<h1>Meeting Notes</h1><p>Discussed the <strong>Q4 roadmap</strong> with the team.</p><ul><li>Launch feature A by Nov 15</li><li>Beta test feature B</li></ul>",
      "preserve_tables": true
    }
  }'

Render Markdown for Email

Convert Markdown content to HTML for sending formatted emails.

# Python - Render markdown for email
import requests

markdown_content = """
# Your Weekly Report

Here's what happened this week:

- **Sales**: Up 15% from last week
- **New signups**: 234 users
- **Support tickets**: 12 resolved

[View full dashboard](https://app.example.com/dashboard)
"""

response = requests.post(
    'https://www.acrewity.com/api/services/execute',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'service': 'markdown-to-html',
        'operation': 'convert',
        'parameters': {
            'content': markdown_content,
            'include_styles': True
        }
    }
)

html_email = response.json()['result']['data']['html']
# Use html_email as the body of your email

Related Services