API Reference
Create Chart
API reference for creating charts programmatically.
Create Chart
Create a new chart with data and styling options.
POST /v1/charts
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
type |
string | Yes |
Chart type: bar, line, pie, area, doughnut |
title |
string | No | Chart title |
subtitle |
string | No | Chart subtitle |
data |
object | Yes | Chart data (see below) |
options |
object | No | Styling options |
template_id |
string | No | Start from a template |
Data Object
{
"labels": ["Jan", "Feb", "Mar"],
"datasets": [
{
"label": "Series 1",
"data": [100, 200, 150],
"color": "#f0b429"
}
]
}
Options Object
{
"colors": ["#f0b429", "#38bdf8", "#4ecdc4"],
"backgroundColor": "#ffffff",
"showLegend": true,
"legendPosition": "bottom",
"showGrid": true,
"animated": false
}
Example Request
curl -X POST https://api.chartpuppy.com/v1/charts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "line",
"title": "Website Traffic",
"subtitle": "Daily visitors in January",
"data": {
"labels": ["Week 1", "Week 2", "Week 3", "Week 4"],
"datasets": [{
"label": "Visitors",
"data": [1250, 1890, 2100, 2450]
}]
},
"options": {
"colors": ["#38bdf8"],
"showGrid": true
}
}'
Response
{
"id": "chart_xyz789",
"type": "line",
"title": "Website Traffic",
"subtitle": "Daily visitors in January",
"url": "https://chartpuppy.com/c/xyz789",
"image_url": "https://chartpuppy.com/c/xyz789.png",
"created_at": "2024-01-15T14:22:00Z",
"updated_at": "2024-01-15T14:22:00Z"
}
Using Templates
Start from a template and override specific values:
curl -X POST https://api.chartpuppy.com/v1/charts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"template_id": "tmpl_monthly_sales",
"data": {
"labels": ["Jan", "Feb", "Mar"],
"datasets": [{
"data": [5000, 7500, 6200]
}]
}
}'
Dynamic Placeholders
Use placeholders in titles that get replaced with current values:
{
"title": "Sales Report - {{current_date}}",
"subtitle": "Total: ${{sum:dataset:0}}"
}
Available placeholders:
| Placeholder | Description |
|---|---|
{{current_date}} |
Today’s date |
{{current_time}} |
Current time |
{{sum:dataset:N}} |
Sum of dataset N |
{{avg:dataset:N}} |
Average of dataset N |
{{max:dataset:N}} |
Maximum value in dataset N |
{{min:dataset:N}} |
Minimum value in dataset N |
Errors
| Code | Description |
|---|---|
400 |
Invalid request body |
401 |
Invalid or missing API key |
422 |
Validation error (check message for details) |
429 |
Rate limit exceeded |