0

Update preferences for text fields on sync flow

by
Published Oct 17, 2025

To enable update of preferences set for the text fields on sync flow.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Update preferences for text fields on sync flow
7
 * To enable update of preferences set for the text fields on sync flow.
8
 */
9
export async function main(auth: Codat, locale: 'en-us' | 'fr-fr' | undefined, body: {}) {
10
	const url = new URL(`https://api.codat.io/sync/commerce/config/ui/text`)
11
	for (const [k, v] of [['locale', locale]]) {
12
		if (v !== undefined && v !== '' && k !== undefined) {
13
			url.searchParams.append(k, v)
14
		}
15
	}
16

17
	const response = await fetch(url, {
18
		method: 'PATCH',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			Authorization: `Basic ${auth.encodedKey}`
22
		},
23
		body: JSON.stringify(body)
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31