Where do I access the API documentation, API token, and Local API?

Where do I access the API documentation, API token, and Local API?

API documentation

Open the AirGradient API documentation.

This lists the available endpoints, required parameters, and response formats. It also lets you inspect and test supported requests.

The API can provide measurements such as PM2.5, temperature, and CO2. Some endpoints can also provide limited historical data or data from public outdoor monitors.

Find your API token

The API token is used for API requests that require authentication. This is for endpoints that return private and not publicly shared data.

Alt text
  1. Open the AirGradient Dashboard.
  2. Open General Settings.
  3. Select the Connectivity tab.
  4. Enable API access.
  5. Copy the API token shown by the dashboard.

You can open the Connectivity settings directly at Connectivity settings.

Treat the API token like a password. Do not share it in screenshots, public repositories, source code, or client-side applications.

Find the Location ID

Some API endpoints require a Location ID. The Location ID identifies the dashboard Location connected to a monitor. It is different from the Location name.

Alt text

To find it:

  1. Open the dashboard's Locations Administration page.
  2. Find the Location connected to your monitor.
  3. Copy the Location ID shown in the first column.

Use the Location ID, rather than the Location name, when an API endpoint asks for it.

How the Local API works

The Local API connects directly to a monitor over your local network. It does not use the AirGradient cloud and does not require a dashboard API token.

Before you start:

  • the monitor must be connected to WiFi
  • the computer or phone making the request must be on the same WiFi network
  • you need the monitor's serial number, shown on the back of the monitor

Get the latest measurements

Open a browser or make an HTTP request to:

http://airgradient_SERIAL_NUMBER.local/measures/current

Replace SERIAL_NUMBER with the serial number of your monitor. For example:

http://airgradient_aaaaaaaaaaaa.local/measures/current
Alt text

The monitor returns the latest measurements in JSON format.

Get the monitor configuration

To retrieve the monitor's local configuration, use:

http://airgradient_SERIAL_NUMBER.local/config

For example:

http://airgradient_aaaaaaaaaaaa.local/config
Alt text

For additional Local API endpoints and implementation details, see the Local Server Documentation.

Which API should I use?

API Use it when... API token required?
Public API You want cloud data, public monitor data, or data from outside the local network. For endpoints that require authentication.
Local API You want direct access to a monitor on the same WiFi network. No.

Related articles

Your are being redirected to AirGradient Dashboard...