0

Get User Forms

by
Published Sep 27, 2024

Gets a list of all forms for an account.

Script jotform Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 621 days ago
1
type Jotform = {
2
	apiKey: string
3
	baseUrl: string
4
}
5

6
export async function main(
7
	resource: Jotform,
8
	params?: {
9
		offset?: number
10
		limit?: number
11
		orderby?:
12
			| 'id'
13
			| 'username'
14
			| 'title'
15
			| 'status'
16
			| 'created_at'
17
			| 'updated_at'
18
			| 'new'
19
			| 'count'
20
			| 'slug'
21
	}
22
) {
23
	const queryParams = new URLSearchParams({ apiKey: resource.apiKey })
24

25
	if (params?.offset) {
26
		queryParams.append('offset', params.offset.toString())
27
	}
28

29
	if (params?.limit) {
30
		queryParams.append('limit', params.limit.toString())
31
	}
32

33
	if (params?.orderby) {
34
		queryParams.append('orderby', params.orderby.toString())
35
	}
36

37
	const endpoint = `${resource.baseUrl}/user/forms?${queryParams.toString()}`
38

39
	const response = await fetch(endpoint, {
40
		method: 'GET',
41
		headers: {
42
			'Content-Type': 'application/json'
43
		}
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