0

Prefix search for places. Useful for autocomplete forms.

by
Published Oct 17, 2025

## Search for places by prefix You can use this endpoint to obtain `place_id` of the location you want, to be used in `point` endpoint.

Script meteosource Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Prefix search for places. Useful for autocomplete forms.
4
 * ## Search for places by prefix
5

6
You can use this endpoint to obtain `place_id` of the location you want, to be used in `point` endpoint.
7
 */
8
export async function main(
9
	auth: RT.Meteosource,
10
	text: string | undefined,
11
	language?: 'cs' | 'en' | 'de' | 'es' | 'fr' | 'pl' | 'pt' | undefined,
12
	key?: string | undefined
13
) {
14
	const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/find_places_prefix`)
15
	for (const [k, v] of [
16
		['text', text],
17
		['language', language],
18
		['key', key]
19
	]) {
20
		if (v !== undefined && v !== '') {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24
	const response = await fetch(url, {
25
		method: 'GET',
26
		headers: {
27
			'X-API-Key': auth.apiKey
28
		},
29
		body: undefined
30
	})
31
	if (!response.ok) {
32
		const text = await response.text()
33
		throw new Error(`${response.status} ${text}`)
34
	}
35
	return await response.json()
36
}
37