Charts in Slack
Two patterns for sending charts to Slack — file upload (recommended) and Block Kit image blocks. Both work in bots and automated workflows.
How it works
Slack supports two ways to display images in channels:
- File upload — POST the PNG bytes to Slack's Files API. Slack hosts the image internally. No public URL needed. Best for most bots.
- Block Kit image block — Pass a public URL. Slack fetches and displays the image. Simpler to implement if the image is publicly accessible.
Use padding: "slack" on your spec for a compact padding preset (12px top and right, 8px bottom and left).
File upload (recommended)
Render the chart to a buffer, then upload it with the Slack SDK. No public URL, no CDN configuration required.
# Step 1: render chart to file
curl -s -X POST https://www.chart-output.com/api/v1/render \
-H "Authorization: Bearer pk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
--output chart.png \
-d '{
"type": "bar",
"width": 800,
"height": 400,
"format": "png",
"padding": "slack",
"brandKitId": "polar",
"data": {
"labels": ["Mon", "Tue", "Wed", "Thu", "Fri"],
"datasets": [{ "label": "Signups", "data": [34, 56, 42, 71, 88] }]
}
}'
# Step 2: upload to Slack
curl -X POST https://slack.com/api/files.getUploadURLExternal \
-H "Authorization: Bearer xoxb-YOUR-SLACK-TOKEN" \
-F "filename=chart.png" \
-F "length=$(wc -c < chart.png)"import { WebClient } from '@slack/web-api';
const slack = new WebClient(process.env.SLACK_BOT_TOKEN);
// Step 1: render the chart to a buffer
const res = await fetch('https://www.chart-output.com/api/v1/render', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHART_OUTPUT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'bar',
width: 800,
height: 400,
format: 'png',
padding: 'slack',
brandKitId: 'polar',
data: {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
datasets: [{ label: 'Signups', data: [34, 56, 42, 71, 88] }],
},
}),
});
const imageBuffer = Buffer.from(await res.arrayBuffer());
// Step 2: upload to Slack
await slack.filesUploadV2({
channel_id: process.env.SLACK_CHANNEL_ID,
file: imageBuffer,
filename: 'chart.png',
title: 'Daily signups',
initial_comment: 'Here\'s the signup trend for this week:',
});import os, json, urllib.request, requests
from slack_sdk import WebClient
slack = WebClient(token=os.environ["SLACK_BOT_TOKEN"])
# Step 1: render
resp = urllib.request.urlopen(urllib.request.Request(
"https://www.chart-output.com/api/v1/render",
data=json.dumps({
"type": "bar",
"width": 800,
"height": 400,
"format": "png",
"padding": "slack",
"brandKitId": "polar",
"data": {
"labels": ["Mon", "Tue", "Wed", "Thu", "Fri"],
"datasets": [{"label": "Signups", "data": [34, 56, 42, 71, 88]}],
},
}).encode(),
headers={
"Authorization": f"Bearer {os.environ['CHART_OUTPUT_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
))
image_bytes = resp.read()
# Step 2: upload to Slack
slack.files_upload_v2(
channel=os.environ["SLACK_CHANNEL_ID"],
content=image_bytes,
filename="chart.png",
title="Daily signups",
initial_comment="Here's the signup trend for this week:",
)Block Kit image block
Use returnUrl: true to get a CDN URL, then pass it to a Slack image block. The URL is publicly accessible and cached — Slack will fetch it once and display it inline.
# Render and get CDN URL
URL=$(curl -s -X POST https://www.chart-output.com/api/v1/render \
-H "Authorization: Bearer pk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"type":"line","width":800,"height":400,"format":"png","returnUrl":true,"data":{"labels":["Jan","Feb","Mar"],"datasets":[{"data":[14200,17800,22900]}]}}' | python3 -c "import sys,json;print(json.load(sys.stdin)['url'])")
# Post to Slack
curl -X POST https://slack.com/api/chat.postMessage \
-H "Authorization: Bearer xoxb-YOUR-SLACK-TOKEN" \
-H "Content-Type: application/json" \
-d "{"channel":"C0123","blocks":[{"type":"image","image_url":"$URL","alt_text":"Chart"}]}"// Return a CDN URL, then reference it in a Slack Block Kit image block
const res = await fetch('https://www.chart-output.com/api/v1/render', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHART_OUTPUT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'line',
width: 800,
height: 400,
format: 'png',
returnUrl: true,
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr'],
datasets: [{ label: 'MRR', data: [14200, 17800, 20100, 22900] }],
},
}),
});
const { url } = await res.json();
// Post to Slack using Block Kit
await slack.chat.postMessage({
channel: process.env.SLACK_CHANNEL_ID,
blocks: [
{
type: 'image',
image_url: url,
alt_text: 'MRR trend',
title: { type: 'plain_text', text: 'Monthly Recurring Revenue' },
},
{
type: 'section',
text: { type: 'mrkdwn', text: '*MRR* is up 22% this month.' },
},
],
});import os, json, urllib.request
from slack_sdk import WebClient
slack = WebClient(token=os.environ["SLACK_BOT_TOKEN"])
resp = urllib.request.urlopen(urllib.request.Request(
"https://www.chart-output.com/api/v1/render",
data=json.dumps({
"type": "line", "width": 800, "height": 400, "format": "png", "returnUrl": True,
"data": {"labels": ["Jan","Feb","Mar","Apr"], "datasets": [{"label":"MRR","data":[14200,17800,20100,22900]}]},
}).encode(),
headers={"Authorization": f"Bearer {os.environ['CHART_OUTPUT_API_KEY']}", "Content-Type": "application/json"},
method="POST",
))
url = json.loads(resp.read())["url"]
slack.chat_postMessage(
channel=os.environ["SLACK_CHANNEL_ID"],
blocks=[
{"type": "image", "image_url": url, "alt_text": "MRR trend",
"title": {"type": "plain_text", "text": "Monthly Recurring Revenue"}},
{"type": "section", "text": {"type": "mrkdwn", "text": "*MRR* is up 22% this month."}},
],
)Full card in Slack
A card composition with header, KPI strip, and the polar brand kit works well as a single image in a Slack message:
{
"type": "bar",
"brandKitId": "polar",
"width": 800,
"height": 420,
"format": "png",
"padding": "slack",
"header": {
"eyebrow": "WEEKLY REPORT",
"title": "Signups",
"badge": { "text": "+14%", "backgroundColor": "rgba(96,165,250,0.15)", "color": "#60a5fa" }
},
"kpiStrip": [
{ "label": "Total", "value": "291" },
{ "label": "Avg/day", "value": "41.6" },
{ "label": "Peak", "value": "88 (Fri)", "color": "#60a5fa" }
],
"data": {
"labels": ["Mon", "Tue", "Wed", "Thu", "Fri"],
"datasets": [{
"label": "Signups",
"data": [34, 56, 42, 71, 88],
"borderRadius": 4
}]
}
}Incoming webhook
If you use Slack's incoming webhooks instead of the bot API, combine returnUrl: true with an image attachment:
const { url } = await renderChart({ returnUrl: true, ...spec });
await fetch(process.env.SLACK_WEBHOOK_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: 'Weekly signups:',
attachments: [{ image_url: url, fallback: 'Signups chart' }],
}),
});Related walkthroughs
Charts for Slack, Discord and Teams bots
Post daily metrics, alerts and reports as real chart images from a bot.
Add a chart to an n8n workflow
Google Sheets rows to a chart image in Slack or email, with one Code node and one HTTP Request node.
Add a chart to a Zapier Zap or Make scenario
Turn a spreadsheet row into a chart image URL and send it to Slack or email.