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

Create an item or multiple items in a CMS Collection across multiple corresponding locales.

Notes:

  • This endpoint can create up to 100 items in a request.
  • If the cmsLocaleIds parameter is undefined or empty and localization is enabled, items will only be created in the primary locale.

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
		cmsLocaleIds?: string[]
12
		lastPublished?: string
13
		lastUpdated?: string
14
		createdOn?: string
15
		isArchived?: false | true
16
		isDraft?: false | true
17
		fieldData?: { name: string; slug: string } | { name: string; slug: string }[]
18
	}
19
) {
20
	const url = new URL(`https://api.webflow.com/v2/collections/${collection_id}/items/bulk`)
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