Update Page Content

This endpoint allows for updating static content on a static page within a secondary locale. It is designed specifically for localized pages and can handle up to 1000 nodes per request. Note:This endpoint is specifically for localized pages. Ensure that the locale specified is a valid secondary locale for the site. Required scope | `pages: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
	page_id: string,
9
	locale: string | undefined,
10
	body: { nodes: { nodeId: string; text: string }[] }
11
) {
12
	const url = new URL(`https://api.webflow.com/v2/pages/${page_id}/dom`)
13

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

20
	const response = await fetch(url, {
21
		method: 'POST',
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