Graph API (Flowcharts)
Generate SVG flowcharts by sending nodes and links as JSON.
POST
POST /graph?apikey={key}
Content-Type: application/json
💡 Note: This endpoint accepts POST only. For GET requests, use the Chart API.
Request Body
| Field | Type | Description |
|---|---|---|
| nodes | array | Array of {"id":"...", "label":"..."} objects (max 50) |
| links | array | Array of {"source":"...", "target":"..."} objects (max 100) |
| options | object | Optional: nodeColor, strokeColor, textColor, bgColor (hex strings, e.g., "#1e293b") |
Options (Customization)
| Option | Type | Description |
|---|---|---|
| nodeColor | string | Node fill color (hex, e.g., #1e293b) |
| strokeColor | string | Border color (hex) |
| textColor | string | Text color (hex) |
| bgColor | string | Background color (hex) |
Code Examples
Copy and paste the code below to get started quickly in your preferred language.
JavaScript (Fetch)
JavaScript
const apiKey = 'YOUR_KEY';
const url = `https://api.divct.workers.dev/graph?apikey=${apiKey}`;
const body = {
nodes: [
{ id: 'start', label: 'Submit' },
{ id: 'review', label: 'Review' },
{ id: 'done', label: 'Done' }
],
links: [
{ source: 'start', target: 'review' },
{ source: 'review', target: 'done' }
]
};
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
})
.then(res => res.text())
.then(svg => {
document.getElementById('graph-container').innerHTML = svg;
})
.catch(err => console.error(err));
Python (Requests)
Python
import requests
api_key = "YOUR_KEY"
url = f"https://api.divct.workers.dev/graph?apikey={api_key}"
body = {
"nodes": [
{"id": "start", "label": "Submit"},
{"id": "review", "label": "Review"},
{"id": "done", "label": "Done"}
],
"links": [
{"source": "start", "target": "review"},
{"source": "review", "target": "done"}
]
}
response = requests.post(url, json=body)
if response.status_code == 200:
with open("flowchart.svg", "wb") as f:
f.write(response.content)
print("Flowchart saved as flowchart.svg")
else:
print("Error:", response.json())
cURL (Command Line)
cURL
curl -X POST "https://api.divct.workers.dev/graph?apikey=YOUR_KEY" \\
-H "Content-Type: application/json" \\
-d '{
"nodes": [
{"id": "start", "label": "Submit"},
{"id": "review", "label": "Review"},
{"id": "done", "label": "Done"}
],
"links": [
{"source": "start", "target": "review"},
{"source": "review", "target": "done"}
]
}' -o flowchart.svg
Node.js (Axios)
Node.js
const axios = require('axios');
const fs = require('fs');
const apiKey = 'YOUR_KEY';
const url = `https://api.divct.workers.dev/graph?apikey=${apiKey}`;
const body = {
nodes: [
{ id: 'start', label: 'Submit' },
{ id: 'review', label: 'Review' },
{ id: 'done', label: 'Done' }
],
links: [
{ source: 'start', target: 'review' },
{ source: 'review', target: 'done' }
]
};
axios.post(url, body, { responseType: 'text' })
.then(res => {
fs.writeFileSync('flowchart.svg', res.data);
console.log('Flowchart saved as flowchart.svg');
})
.catch(err => console.error(err));
Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | INVALID_DATA | Invalid nodes or links |
| 401 | UNAUTHORIZED | Missing or invalid API key |
| 403 | DOMAIN_NOT_ALLOWED | API key restricted to specific domains |
| 403 | INVALID_SIGNATURE | Request signature verification failed |
| 403 | FORBIDDEN | Request blocked (e.g., restricted key usage) |
| 403 | ACCOUNT_SUSPENDED | Account has been suspended |
| 429 | RATE_LIMITED | Too many requests |
| 429 | QUOTA_EXCEEDED | Points quota exhausted (includes Retry-After header) |
| 500 | INTERNAL_ERROR | Internal server error |
| 503 | SERVICE_UNAVAILABLE | Graph generation service down |
Example
POST
POST /graph?apikey=YOUR_KEY
Content-Type: application/json
{
"nodes": [
{"id":"start","label":"Submit"},
{"id":"review","label":"Review"},
{"id":"done","label":"Done"}
],
"links": [
{"source":"start","target":"review"},
{"source":"review","target":"done"}
],
"options": {
"nodeColor": "#1e293b",
"strokeColor": "#38bdf8",
"textColor": "#f8fafc",
"bgColor": "#0f172a"
}
}
Example Result
Flowchart
Limits
- Maximum 50 nodes
- Maximum 100 links
- Links must reference valid node IDs