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

Remove a live item from the site. Removing a published item will unpublish the item from the live site and set it to draft. This endpoint does not currently support bulk deletion. Required scope | CMS:write

Created by hugo697 514 days ago
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
	item_id: string,
10
	cmsLocaleId: string | undefined
11
) {
12
	const url = new URL(
13
		`https://api.webflow.com/v2/collections/${collection_id}/items/${item_id}/live`
14
	)
15

16
	for (const [k, v] of [['cmsLocaleId', cmsLocaleId]]) {
17
		if (v !== undefined && v !== '' && k !== undefined) {
18
			url.searchParams.append(k, v)
19
		}
20
	}
21

22
	const response = await fetch(url, {
23
		method: 'DELETE',
24
		headers: {
25
			Authorization: 'Bearer ' + auth.token
26
		},
27
		body: undefined
28
	})
29

30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34

35
	return await response.text()
36
}
37