> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAQ

> Client-mode REST API connector for a curated OpenAQ v3 slice: list locations and read latest measurements

Technical Preview

# OpenAQ

Client-mode REST API connector for a curated OpenAQ v3 slice: list locations and read latest measurements.

* Hub category: **Public data**.
* Base: `https://api.openaq.org`

## Template reference

Generated from the shipped broker template `openaq` (`-routeCode OPENAQ`). It lists every event the template defines.

### Auth

Auth headers used by the template: `X-API-Key: Bearer {value.json.api_token}`.

### Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the OpenAQ connector | no |
| `BaseUrl` | string | OpenAQ base URL without trailing slash (e.g. [https://api.openaq.org](https://api.openaq.org)) | yes |

`BASE_ADDRESS` default: `https://api.openaq.org`.

### Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `Listlocations` | GET | `/v3/locations` | `public/openaq/locations/list` | `public/openaq/locations/list/response` | `api_token` |
| `Getlatest` | GET | `/v3/locations/{value.json.location_id}/latest` | `public/openaq/locations/latest` | `public/openaq/locations/latest/response` | `api_token`, `location_id` |

### Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode OPENAQ"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE OpenAqRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://api.openaq.org"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Listlocations
        WITH SOURCE_TOPIC "public/openaq/locations/list"
        WITH DESTINATION_TOPIC "public/openaq/locations/list/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v3/locations"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "X-API-Key" "Bearer {value.json.api_token}"
    ADD EVENT Getlatest
        WITH SOURCE_TOPIC "public/openaq/locations/latest"
        WITH DESTINATION_TOPIC "public/openaq/locations/latest/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v3/locations/{value.json.location_id}/latest"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "X-API-Key" "Bearer {value.json.api_token}"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

### Usage example

Call `Listlocations` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'public/openaq/locations/list/response' &
mosquitto_pub -t 'public/openaq/locations/list' -m '{"api_token": "<api_token>"}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.