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

Create live Item in a Collection. This Item will be published to the live site. To create items across multiple locales, please use this endpoint. 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
	body: {
10
		id: string
11
		cmsLocaleId?: string
12
		lastPublished?: string
13
		lastUpdated?: string
14
		createdOn?: string
15
		isArchived?: false | true
16
		isDraft?: false | true
17
		fieldData?: { name?: string; slug?: string }
18
	}
19
) {
20
	const url = new URL(`https://api.webflow.com/v2/collections/${collection_id}/items/live`)
21

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

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

36
	return await response.json()
37
}
38