Update User
One script reply has been approved by the moderators Verified

Update a User by ID Required scope | users:write The email and password fields cannot be updated using this endpoint

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
	site_id: string,
9
	user_id: string,
10
	body: {
11
		data?: {
12
			name?: string
13
			'accept-privacy'?: false | true
14
			'accept-communications'?: false | true
15
		}
16
		accessGroups?: string[]
17
	}
18
) {
19
	const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/users/${user_id}`)
20

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

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

35
	return await response.json()
36
}
37