API Documentation

← Back to home

Overview

Chart Crafter provides REST API endpoints to create, manage, and visualize charts. All API access requires HTTPS and returns JSON responses.

Authentication

Password Protection

Each chart creation returns a deletion password in the response. Include this in the X-Delete-Password header for deletion requests.

Master Key

Admins can use the MASTER_KEY environment variable with a Bearer token for full access to all operations.

Endpoints

POST /api/chart

Create a new chart entry. Example request:

curl -X POST https://chart-crafter.ideocanvas.com/api/chart \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Usage Stats",
    "description": "Weekly usage metrics",
    "expiresIn": "7d",
    "data": {
      "xAxis": { "type": "category", "data": ["Mon", "Tue", "Wed"] },
      "yAxis": { "type": "value" },
      "series": [{ "data": [10, 20, 30], "type": "bar" }]
    }
  }'

DELETE /api/chart/{id}

Delete a chart using either method:

curl -X DELETE https://chart-crafter.ideocanvas.com/api/chart/123 \
  -H "Authorization: Bearer $MASTER_KEY"

or

curl -X DELETE https://chart-crafter.ideocanvas.com/api/chart/123 \
  -H "X-Delete-Password: chart-password"

Data Format

ECharts Configuration

The data field should contain valid ECharts configuration. Example minimal configuration:

{
  "xAxis": {
    "type": "category",
    "data": ["Q1", "Q2", "Q3", "Q4"]
  },
  "yAxis": {
    "type": "value"
  },
  "series": [{
    "data": [120, 200, 150, 80],
    "type": "line"
  }]
}

API Response Formats

POST /api/chart Response

{
  "id": "20240614-123e4567-e89b-12d3-a456-426614174000",
  "url": "https://example.com/chart/20240614-123e4567-e89b-12d3-a456-426614174000/",
  "thumbnail": "https://example.com/api/chart/image/20240614-123e4567-e89b-12d3-a456-426614174000/",
  "password": "aBcDeFgHiJkL",
  "svg": "<svg>...vector image data...</svg>"
}

GET /api/chart Response

{
  "chart": [
    {
      "id": "20240614-123e4567-e89b-12d3-a456-426614174000",
      "name": "Usage Stats",
      "url": "https://example.com/chart/20240614-123e4567-e89b-12d3-a456-426614174000",
      "thumbnail": "https://example.com/api/chart/image/20240614-123e4567-e89b-12d3-a456-426614174000",
      "createdAt": "2024-06-14T09:30:00Z",
      "expiresAt": 1718352000000,
      "status": "active"
    },
    {
      "id": "20240613-98765432-1234-5678-9012-345678901234",
      "name": "Old Chart",
      "url": "https://example.com/chart/20240613-98765432-1234-5678-9012-345678901234",
      "thumbnail": "https://example.com/api/chart/image/20240613-98765432-1234-5678-9012-345678901234",
      "createdAt": "2024-06-13T15:45:00Z",
      "expiresAt": 1718200000000,
      "status": "expired"
    }
  ]
}

Best Practices

📅 Expiration Times

  • Use shorter durations (1-24h) for sensitive data
  • Maximum expiry is 30 days
  • Expired charts are automatically purged

🔐 Security

  • Always use HTTPS for API calls
  • Store deletion passwords securely
  • Rotate master keys periodically