0

Update Dropdown, Multiple Choice or Ranking

by
Published Mar 25, 2024

Update a dropdown, multiple choice, or ranking field's choices. [See the docs here](https://developer.typeform.com/create/reference/update-form/)

Script typeform Verified

The script

Submitted by hugo697 Bun
Verified 399 days ago
1
import { createClient } from '@typeform/api-client'
2

3
type Typeform = {
4
	token: string
5
	baseUrl: string
6
}
7

8
export async function main(
9
	resource: Typeform,
10
	data: {
11
		id: string
12
		fields?: {
13
			id?: string
14
			ref?: string
15
			title?: string
16
			type?:
17
				| 'address'
18
				| 'calendly'
19
				| 'contact_info'
20
				| 'date'
21
				| 'dropdown'
22
				| 'email'
23
				| 'file_upload'
24
				| 'group'
25
				| 'legal'
26
				| 'long_text'
27
				| 'matrix'
28
				| 'multiple_choice'
29
				| 'nps'
30
				| 'number'
31
				| 'opinion_scale'
32
				| 'payment'
33
				| 'phone_number'
34
				| 'picture_choice'
35
				| 'ranking'
36
				| 'rating'
37
				| 'short_text'
38
				| 'statement'
39
				| 'website'
40
				| 'yes_no'
41
			properties?: {
42
				description?: string
43
				choices?: {
44
					id?: string
45
					ref?: string
46
					label?: string
47
					attachment?: {
48
						type?: 'image' | 'video'
49
						href?: string
50
						scale?: 0.4 | 0.6 | 0.8 | 1
51
					}
52
				}[]
53
				fields?: any[]
54
				allow_multiple_selection?: boolean
55
				randomize?: boolean
56
				allow_other_choice?: boolean
57
				vertical_alignment?: boolean
58
				supersized?: boolean
59
				show_labels?: boolean
60
				alphabetical_order?: boolean
61
				hide_marks?: boolean
62
				button_text?: string
63
				steps?: 5 | 6 | 7 | 8 | 9 | 10 | 11
64
				shape?:
65
					| 'cat'
66
					| 'circle'
67
					| 'cloud'
68
					| 'crown'
69
					| 'dog'
70
					| 'droplet'
71
					| 'flag'
72
					| 'heart'
73
					| 'lightbulb'
74
					| 'pencil'
75
					| 'skull'
76
					| 'star'
77
					| 'thunderbolt'
78
					| 'tick'
79
					| 'trophy'
80
					| 'up'
81
					| 'user'
82
				labels?: {
83
					left?: string
84
					right?: string
85
					center?: string
86
				}
87
				start_at_one?: boolean
88
				structure?: 'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD'
89
				separator?: '/' | '-' | '.'
90
				currency?:
91
					| 'AUD'
92
					| 'BRL'
93
					| 'CAD'
94
					| 'CHF'
95
					| 'DKK'
96
					| 'EUR'
97
					| 'GBP'
98
					| 'MXN'
99
					| 'NOK'
100
					| 'SEK'
101
					| 'USD'
102
			}
103
			validations?: {
104
				required?: boolean
105
				max_length?: number
106
				min_value?: number
107
				max_value?: number
108
			}
109
			attachment?: {
110
				type?: 'image' | 'video'
111
				href?: string
112
				scale?: 0.4 | 0.6 | 0.8 | 1
113
			}
114
		}[]
115
	}
116
) {
117
	const typeformAPI = createClient({
118
		token: resource.token,
119
		apiBaseUrl: resource.baseUrl
120
	})
121

122
	return await typeformAPI.forms.update({
123
		uid: data.id,
124
		override: true,
125
		// @ts-ignore
126
		data
127
	})
128
}
129