0

Get Form Submissions

by
Published Sep 27, 2024

Gets a list of form responses.

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
	formId: string,
9
	params?: {
10
		offset?: number
11
		limit?: number
12
		orderby?:
13
			| 'id'
14
			| 'username'
15
			| 'title'
16
			| 'status'
17
			| 'created_at'
18
			| 'updated_at'
19
			| 'new'
20
			| 'count'
21
			| 'slug'
22
	}
23
) {
24
	const queryParams = new URLSearchParams({ apiKey: resource.apiKey })
25

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

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

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

38
	const endpoint = `${resource.baseUrl}/form/${formId}/submissions?${queryParams.toString()}`
39

40
	const response = await fetch(endpoint, {
41
		method: 'GET',
42
		headers: {
43
			'Content-Type': 'application/json'
44
		}
45
	})
46

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

51
	const data = await response.json()
52

53
	return data
54
}
55