0
Update Live Collection Item
One script reply has been approved by the moderators Verified

Update a selected live Item in a Collection. The updates for this Item will be published to the live site. Required scope | CMS:write

Created by hugo697 253 days ago Viewed 13480 times
0
Submitted by hugo697 Bun
Verified 253 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
	item_id: string,
10
	body: {
11
		id: string
12
		cmsLocaleId?: string
13
		lastPublished?: string
14
		lastUpdated?: string
15
		createdOn?: string
16
		isArchived?: false | true
17
		isDraft?: false | true
18
		fieldData?: { name?: string; slug?: string }
19
	}
20
) {
21
	const url = new URL(
22
		`https://api.webflow.com/v2/collections/${collection_id}/items/${item_id}/live`
23
	)
24

25
	const response = await fetch(url, {
26
		method: 'PATCH',
27
		headers: {
28
			'Content-Type': 'application/json',
29
			Authorization: 'Bearer ' + auth.token
30
		},
31
		body: JSON.stringify(body)
32
	})
33

34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38

39
	return await response.json()
40
}
41