0

Retrieve preferences for text fields on sync flow

by
Published Oct 17, 2025

To enable retrieval 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
 * Retrieve preferences for text fields on sync flow
7
 * To enable retrieval of preferences set for the text fields on Sync Flow.
8
 */
9
export async function main(auth: Codat, locale: 'en-us' | 'fr-fr' | undefined) {
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: 'GET',
19
		headers: {
20
			Authorization: `Basic ${auth.encodedKey}`
21
		},
22
		body: undefined
23
	})
24
	if (!response.ok) {
25
		const text = await response.text()
26
		throw new Error(`${response.status} ${text}`)
27
	}
28
	return await response.json()
29
}
30