0
Custom Fields: Update Field
One script reply has been approved by the moderators Verified

Update a custom field

Created by hugo697 25 days ago Viewed 10 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 25 days ago
1
type Convertkit = {
2
	apiSecret: string
3
}
4

5
export async function main(resource: Convertkit, customFieldId: string, label: string) {
6
	const endpoint = `https://api.convertkit.com/v3/custom_fields/${customFieldId}`
7

8
	const body = {
9
		api_secret: resource.apiSecret,
10
		label
11
	}
12

13
	const response = await fetch(endpoint, {
14
		method: 'PUT',
15
		headers: {
16
			'Content-Type': 'application/json'
17
		},
18
		body: JSON.stringify(body)
19
	})
20

21
	if (!response.ok) {
22
		throw new Error(`HTTP error! status: ${response.status}`)
23
	}
24

25
	return { success: true }
26
}
27