0

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

by
Published Oct 17, 2025

## Current weather and forecast for 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 weather data for a single point (geographic name or GPS)
4
 * ## Current weather and forecast for 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
	sections?: string | undefined,
15
	timezone?: string | undefined,
16
	language?: 'cs' | 'en' | 'de' | 'es' | 'fr' | 'pl' | 'pt' | undefined,
17
	units?: 'auto' | 'metric' | 'us' | 'uk' | 'ca' | undefined,
18
	key?: string | undefined
19
) {
20
	const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/point`)
21
	for (const [k, v] of [
22
		['place_id', place_id],
23
		['lat', lat],
24
		['lon', lon],
25
		['sections', sections],
26
		['timezone', timezone],
27
		['language', language],
28
		['units', units],
29
		['key', key]
30
	]) {
31
		if (v !== undefined && v !== '') {
32
			url.searchParams.append(k, v)
33
		}
34
	}
35
	const response = await fetch(url, {
36
		method: 'GET',
37
		headers: {
38
			'X-API-Key': auth.apiKey
39
		},
40
		body: undefined
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48