0

Retrieve Activities

by
Published Oct 11, 2024

This endpoint returns all activity data.

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
	options?: {
10
		filter?: Array<Record<string, any>>
11
		sort?: Array<Record<string, any>>
12
		limit?: number
13
		offset?: number
14
	}
15
) {
16
	const endpoint = `https://api.zixflow.com/api/v1/collection-records/activity-list/query`
17

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

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

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

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

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

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

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

49
	const data = await response.json()
50

51
	return data
52
}
53