Register Script - Inline

Add a script to a Site's Custom Code registry. Inline scripts can be between 1 and 2000 characters. In order to use the Custom Code APIs for Sites and Pages, Custom Code Scripts must first be registered to a Site via the `registered_scripts` endpoints, and then applied to a Site or Page using the appropriate `custom_code` endpoints. Access to this endpoint requires a bearer token from a Data Client App. Required scope | `custom_code:write`

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
	body: {
10
		sourceCode: string
11
		integrityHash?: string
12
		canCopy?: false | true
13
		version: string
14
		displayName: string
15
	}
16
) {
17
	const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/registered_scripts/inline`)
18

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

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

33
	return await response.json()
34
}
35