0
List Sources
One script reply has been approved by the moderators Verified
Created by hugo697 117 days ago Viewed 167 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 117 days ago
1
type Baremetrics = {
2
	apiKey: string
3
}
4

5
export async function main(
6
	resource: Baremetrics,
7
	params?: {
8
		page?: number
9
		per_page?: number
10
	}
11
) {
12
	const queryParams = new URLSearchParams()
13

14
	if (params?.page) {
15
		queryParams.append('page', params.page.toString())
16
	}
17

18
	if (params?.per_page) {
19
		queryParams.append('per_page', params.per_page.toString())
20
	}
21

22
	const endpoint = `https://api.baremetrics.com/v1/sources?${queryParams.toString()}`
23

24
	const response = await fetch(endpoint, {
25
		method: 'GET',
26
		headers: {
27
			'Content-Type': 'application/json',
28
			Accept: 'application/json',
29
			Authorization: `Bearer ${resource.apiKey}`
30
		}
31
	})
32

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

37
	const data = await response.json()
38

39
	return data
40
}
41