0

Retrieve Location Details

by
Published Nov 5, 2024

Retrieves information about a location.

Script tripadvisor Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Tripadvisor = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	resource: Tripadvisor,
8
	locationId: string,
9
	options?: {
10
		language: string
11
		currency: string
12
	}
13
) {
14
	const queryParams = new URLSearchParams({
15
		key: resource.apiKey
16
	})
17

18
	if (options?.language) {
19
		queryParams.append('language', options.language)
20
	}
21

22
	if (options?.currency) {
23
		queryParams.append('currency', options.currency)
24
	}
25

26
	const endpoint = `https://api.content.tripadvisor.com/api/v1/location/${locationId}/details?${queryParams.toString()}`
27

28
	const response = await fetch(endpoint, {
29
		method: 'GET',
30
		headers: {
31
			accept: 'application/json'
32
		}
33
	})
34

35
	if (!response.ok) {
36
		throw new Error(`HTTP error! status: ${response.status}`)
37
	}
38

39
	const data = await response.json()
40

41
	return data
42
}
43