List Custom Code Blocks

Get all instances of Custom Code applied to a Site or Pages. Access to this endpoint requires a bearer token from a Data Client App. Required scope | `custom_code:read`

Script webflow Verified

by hugo697 ยท 11/5/2024

The script

Submitted by hugo697 Bun
Verified 563 days ago
1
//native
2
type Webflow = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Webflow,
8
	site_id: string,
9
	offset: string | undefined,
10
	limit: string | undefined
11
) {
12
	const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/custom_code/blocks`)
13

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

23
	const response = await fetch(url, {
24
		method: 'GET',
25
		headers: {
26
			Authorization: 'Bearer ' + auth.token
27
		},
28
		body: undefined
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