Update Live Collection Items

Update a single live item or multiple live items (up to 100) in a Collection **Note:** If the `cmsLocaleId` parameter is undefined or empty and the items are localized, items will be updated only in the primary locale. Required scope | `CMS:write`

Script webflow Verified

by hugo697 ยท 11/5/2024

The script

Submitted by hugo697 Bun
Verified 564 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
	body: {
10
		items?: {
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
) {
22
	const url = new URL(`https://api.webflow.com/v2/collections/${collection_id}/items/live`)
23

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

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

38
	return await response.json()
39
}
40