0

Retrieve List Entries

by
Published Oct 11, 2024

This endpoint returns all entry data of selected list.

Script zixflow Verified

The script

Submitted by hugo697 Bun
Verified 606 days ago
1
//native
2

3
type Zixflow = {
4
	apiKey: string
5
}
6

7
export async function main(
8
	resource: Zixflow,
9
	listId: string,
10
	options?: {
11
		filter?: Array<Record<string, any>>
12
		sort?: Array<Record<string, any>>
13
		limit?: number
14
		offset?: number
15
	}
16
) {
17
	const endpoint = `https://api.zixflow.com/api/v1/list-entries/${listId}/query`
18

19
	const body: Record<string, any> = {}
20

21
	if (options?.filter) {
22
		body.filter = options.filter
23
	}
24

25
	if (options?.sort) {
26
		body.sort = options.sort
27
	}
28

29
	if (options?.limit) {
30
		body.limit = options.limit
31
	}
32

33
	if (options?.offset) {
34
		body.offset = options.offset
35
	}
36

37
	const response = await fetch(endpoint, {
38
		method: 'POST',
39
		headers: {
40
			Authorization: `Bearer ${resource.apiKey}`,
41
			'Content-Type': 'application/json'
42
		},
43
		body: JSON.stringify(body)
44
	})
45

46
	if (!response.ok) {
47
		throw new Error(`HTTP error! status: ${response.status}`)
48
	}
49

50
	const data = await response.json()
51

52
	return data
53
}
54