Update Collection Field
One script reply has been approved by the moderators Verified

Update a custom field in a collection. Required scope | cms:write

Created by hugo697 514 days ago Picked 1 time
Submitted by hugo697 Bun
Verified 514 days ago
1
//native
2
type Webflow = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Webflow,
8
	collection_id: string,
9
	field_id: string,
10
	body: { isRequired?: false | true; displayName?: string; helpText?: string }
11
) {
12
	const url = new URL(`https://api.webflow.com/v2/collections/${collection_id}/fields/${field_id}`)
13

14
	const response = await fetch(url, {
15
		method: 'PATCH',
16
		headers: {
17
			'Content-Type': 'application/json',
18
			Authorization: 'Bearer ' + auth.token
19
		},
20
		body: JSON.stringify(body)
21
	})
22

23
	if (!response.ok) {
24
		const text = await response.text()
25
		throw new Error(`${response.status} ${text}`)
26
	}
27

28
	return await response.json()
29
}
30