Update Item Inventory
One script reply has been approved by the moderators Verified

Updates the current inventory levels for a particular SKU item. Updates may be given in one or two methods, absolutely or incrementally. Absolute updates are done by setting quantity directly. Incremental updates are by specifying the inventory delta in updateQuantity which is then added to the quantity stored on the server.

Required scope | ecommerce: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
	body: {
11
		inventoryType: 'infinite' | 'finite'
12
		updateQuantity?: number
13
		quantity?: number
14
	}
15
) {
16
	const url = new URL(
17
		`https://api.webflow.com/v2/collections/${collection_id}/items/${item_id}/inventory`
18
	)
19

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

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

34
	return await response.json()
35
}
36