A Simple Guide to Retrieving IDs from the AirQo API
In this quick guide, we’ll walk you through the steps to get key identifiers like Site IDs and Grid IDs easily, making it a handy reference as you use the AirQo API for your next air quality data project!
Step 1: Get Authenticated
Before diving into the API, you need an access token. Here’s how to set it up:
Sign Up: Head to the AirQo Analytics and create an account.
Register a Client: Log in, go to the settings page, find the API tab, and register a new client to get your credentials.
Generate a Token: Use those credentials to generate an access token. You’ll need to include this token as a token parameter in every API request.
Once you’ve got your token, you’re ready to fetch those IDs!
Step 2: Retrieve Site and Grid IDs
Here’s how:
Endpoint: Send a GET request to api.airqo.net/api/v2/devices/grids/summary?...
What You’ll Get: A JSON response with a list of grids, each containing sites. It might look something like this:
{
"success": true,
"message": "Successfull Operation",
"grids": [
{
"_id": "65e98e11528c9f00133444f8",
"visibility": true,
"name": "ethiopia",
"admin_level": "country",
"network": "airqo",
"long_name": "Ethiopia",
"createdAt": "2024-03-07T09:51:13.703Z",
"sites": [
{
"_id": "637392727c737c001e785545",
"formatted_name": "2R6C+GJF, Jacros - Salite Mehret Rd, Addis Ababa, Ethiopia",
"parish": "Bole",
"sub_county": "Bole",
"city": "Addis Ababa",
"region": "Addis Ababa",
"country": "Ethiopia",
"name": "U.S. Department of State Ethiopia - Addis Ababa",
"approximate_latitude": 9.007071093631989,
"approximate_longitude": 38.819870427611285,
"location_name": "Ethiopia",
"search_name": "Addis Ababa",
"data_provider": "US Embassy"
},
{Site 2},
{Site 3},
{Site 4}
],
"numberOfSites": 6
},
{Grid 2},
{Grid 3},
{Grid 4}
}
How to Use It:
For Grid IDs, grab the _id from each grid object.
For Site IDs, dig into the sites array and take the _id from each site.
Wrapping Up
Got feedback? Let us know—we’d love to keep this guide fresh.
Happy coding, and may your air quality data always be insightful!