0

Returns air quality data for a single point (geographic name or GPS)

by
Published Oct 17, 2025

## Air quality forecast for a single location ### Location specification The location of the weather data is the only parameter that is required and must be specified.

Script meteosource Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Returns air quality data for a single point (geographic name or GPS)
4
 * ## Air quality forecast for a single location
5

6
### Location specification
7
The location of the weather data is the only parameter that is required and must be specified.
8
 */
9
export async function main(
10
	auth: RT.Meteosource,
11
	place_id?: string | undefined,
12
	lat?: string | undefined,
13
	lon?: string | undefined,
14
	timezone?: string | undefined,
15
	key?: string | undefined
16
) {
17
	const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/air_quality`)
18
	for (const [k, v] of [
19
		['place_id', place_id],
20
		['lat', lat],
21
		['lon', lon],
22
		['timezone', timezone],
23
		['key', key]
24
	]) {
25
		if (v !== undefined && v !== '') {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			'X-API-Key': auth.apiKey
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.json()
41
}
42