0
List Purchases
One script reply has been approved by the moderators Verified

Returns a list of all purchases

Created by hugo697 25 days ago Viewed 10 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 25 days ago
1
type Convertkit = {
2
	apiSecret: string
3
}
4

5
export async function main(
6
	resource: Convertkit,
7
	filter?: {
8
		page: number
9
	}
10
) {
11
	const queryParams = new URLSearchParams({
12
		api_secret: resource.apiSecret
13
	})
14

15
	if (filter?.page) queryParams.append('page', filter.page.toString())
16

17
	const endpoint = `https://api.convertkit.com/v3/purchases?${queryParams.toString()}`
18

19
	const response = await fetch(endpoint, {
20
		method: 'GET',
21
		headers: {
22
			'Content-Type': 'application/json'
23
		}
24
	})
25

26
	if (!response.ok) {
27
		throw new Error(`HTTP error! status: ${response.status}`)
28
	}
29

30
	const data = await response.json()
31

32
	return data
33
}
34