Open source Enterprise Grafana Cloud

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

  1. In Grafana, navigate to Connections > Data sources.
  2. Click Add new data source and select Infinity.
  3. In Allowed hosts, enter https://thingspeak.com.
  4. For private channels, expand Authentication and select API Key.
    • Set Key to api_key and add your ThingSpeak Read API Key.
    • Set Add to to Query String.
  5. 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:

SettingValue
TypeJSON
URLhttps://thingspeak.com/channels/38629/feed.json
ParserBackend
Root selectorfeeds

Columns:

SelectorAliasType
created_atTimeTimestamp
field1Field 1Number
field2Field 2Number

CSV format

Configuration:

SettingValue
TypeCSV
URLhttps://thingspeak.com/channels/38629/feed.csv

The CSV format automatically detects column headers.

XML format

Configuration:

SettingValue
TypeXML
URLhttps://thingspeak.com/channels/38629/feed.xml
Root selectorchannel.feeds.feed

Columns:

SelectorAliasType
created-atTimeTimestamp
field1Field 1Number

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=60

Aggregation options

ParameterDescription
average=NAverage values over N minutes
sum=NSum values over N minutes
median=NMedian values over N minutes
timescale=NTimescale values over N minutes

Valid aggregation intervals

MinutesDuration
1010 minutes
1515 minutes
2020 minutes
3030 minutes
601 hour
2404 hours
72012 hours
14401 day

For example, average=1440 calculates the daily average.

ThingSpeak URL parameters

ParameterDescriptionExample
resultsNumber of results to returnresults=100
startStart date/timestart=2024-01-01
endEnd date/timeend=2024-01-31
timezoneTimezone for timestampstimezone=America/New_York
statusInclude status fieldstatus=true

Troubleshoot

IssueCauseSolution
Empty responsePrivate channel without API keyAdd your Read API Key in authentication settings
No data for time rangeTime range > 2 hours without aggregationAdd an aggregation parameter (average, sum, median)
Field values are nullSensor not reporting that fieldVerify the field exists in your ThingSpeak channel
400 Bad RequestInvalid aggregation intervalUse a valid interval (10, 15, 20, 30, 60, 240, 720, 1440)

Additional resources