0

Get User Submissions

by
Published Sep 27, 2024

Gets a list of all submissions for all forms on the 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?: 'id' | 'form_id' | 'IP' | 'created_at' | 'status' | 'new' | 'flag' | 'updated_at'
12
	}
13
) {
14
	const queryParams = new URLSearchParams({ apiKey: resource.apiKey })
15

16
	if (params?.offset) {
17
		queryParams.append('offset', params.offset.toString())
18
	}
19

20
	if (params?.limit) {
21
		queryParams.append('limit', params.limit.toString())
22
	}
23

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

28
	const endpoint = `${resource.baseUrl}/user/submissions?${queryParams.toString()}`
29

30
	const response = await fetch(endpoint, {
31
		method: 'GET',
32
		headers: {
33
			'Content-Type': 'application/json'
34
		}
35
	})
36

37
	if (!response.ok) {
38
		throw new Error(`HTTP error! status: ${response.status}`)
39
	}
40

41
	const data = await response.json()
42

43
	return data
44
}
45