Generate Image
Generate chart images using customizable templates and data parameters.
Endpoint
POST https://api.instacharts.io/v1/generate/imageAuthorization
This endpoint requires OAuth 2.0 authentication. Include your access token in the Authorization header:
Authorization: Bearer your_access_tokenRequest Parameters
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer token obtained through OAuth 2.0 |
Content-Type | Yes | Must be application/json |
Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
templateId | string | Yes | Unique identifier of the chart template |
chartType | string | No | Type of chart (default: “stackedBar”). Chart Types |
x | array | Yes | X-axis data object Ex: ["Mobile", "Desktop", "Tablet"] |
y | array | Yes | Y-axis data object Ex: [100, 200, 400] |
z | array | Yes (if unaggregated data is chosen and the chart type has a breakdown) | Breakdown axis data object Ex: ["Site A", "Site A", "Site B"] |
series | array | Yes (if series data is chosen) | Series data. An array of objects each with a label and data array Ex:[{label:"Site A",data:[1,2,3]},{label:"Site B",data:[4,5,6]}] |
title | string | No | Main chart title |
subtitle | string | No | Secondary chart title |
xTitle | string | No | X-Axis title |
yTitle | string | No | Y-Axis title |
zTitle | string | No | Legend title |
dLabel | string | No | Show Data Labels near the chart pieces Ex: dLabel=true |
overrides | string | No | Any query params not defined above. Join parameters with & Ex: color=cccccc&width=500 |
Example Requests
Basic Line Chart
{ "templateId": "basic-line", "chartType": "line", "title": "Monthly Sales 2024", "subtitle": "Revenue by Product Category", "x": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"], "xTitle": "Month", "yTitle": "Revenue ($)", "y": [1200, 1900, 2100, 2400, 2800, 3100]}Responses
Success Response
HTTP/1.1 200 OKContent-Type: image/pngThe response body will contain the binary image data in the requested format.
Error Responses
Error responses are plain text in the response body, not a JSON object.
Invalid Request or Render Error (400)
HTTP/1.1 400 Bad RequestContent-Type: text/plain
Error serving imageThe body text varies with the underlying problem (for example an invalid or missing templateId).
Out of Tasks (400)
HTTP/1.1 400 Bad RequestContent-Type: text/plain
Out of tasksReturned when your account has used its full monthly task allowance. Each successful image generation counts as one task.
Authentication Error (401)
{ "error": "invalid_token"}