ThingSpeak API
Connect to the ThingSpeak IoT platform to visualize sensor data and metrics from your IoT devices.
Before you begin
- A ThingSpeak channel with data (public channels work without authentication)
- For private channels, your ThingSpeak Read API Key
- Know your channel ID
This guide uses the public traffic monitor channel (Channel ID: 38629) for examples.
Configure the data source
- In Grafana, navigate to Connections > Data sources.
- Click Add new data source and select Infinity.
- In Allowed hosts, enter
https://thingspeak.com. - For private channels, expand Authentication and select API Key.
- Set Key to
api_keyand add your ThingSpeak Read API Key. - Set Add to to Query String.
- Set Key to
- Click Save & test.
Query examples
ThingSpeak provides data in JSON, CSV, and XML formats. Choose the format that best fits your needs.
JSON format
Configuration:
Columns:
CSV format
Configuration:
The CSV format automatically detects column headers.
XML format
Configuration:
Columns:
Filter by dashboard time range
By default, ThingSpeak returns recent data regardless of your Grafana time range. To filter by the dashboard time range, add time parameters to the URL:
https://thingspeak.com/channels/38629/feed.json?start=${__from:date:YYYY-MM-DD HH:NN:SS}&end=${__to:date:YYYY-MM-DD HH:NN:SS}This uses Grafana’s time variables to pass the selected time range to the API.
Query long time ranges
For time ranges longer than 2 hours, ThingSpeak requires data aggregation. Add an aggregation parameter:
https://thingspeak.com/channels/38629/feed.json?start=${__from:date:YYYY-MM-DD HH:NN:SS}&end=${__to:date:YYYY-MM-DD HH:NN:SS}&average=60Aggregation options
Valid aggregation intervals
For example, average=1440 calculates the daily average.



