0

Update all sync settings

by
Published Oct 17, 2025

Update sync settings for all data types.

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 all sync settings
7
 * Update sync settings for all data types.
8
 */
9
export async function main(
10
	auth: Codat,
11
	body: {
12
		clientId: string
13
		settings: {
14
			dataType:
15
				| 'accountTransactions'
16
				| 'balanceSheet'
17
				| 'bankAccounts'
18
				| 'bankTransactions'
19
				| 'billCreditNotes'
20
				| 'billPayments'
21
				| 'bills'
22
				| 'cashFlowStatement'
23
				| 'chartOfAccounts'
24
				| 'company'
25
				| 'creditNotes'
26
				| 'customers'
27
				| 'directCosts'
28
				| 'directIncomes'
29
				| 'invoices'
30
				| 'itemReceipts'
31
				| 'items'
32
				| 'journalEntries'
33
				| 'journals'
34
				| 'paymentMethods'
35
				| 'payments'
36
				| 'profitAndLoss'
37
				| 'purchaseOrders'
38
				| 'salesOrders'
39
				| 'suppliers'
40
				| 'taxRates'
41
				| 'trackingCategories'
42
				| 'transfers'
43
				| 'banking-accountBalances'
44
				| 'banking-accounts'
45
				| 'banking-transactionCategories'
46
				| 'banking-transactions'
47
				| 'commerce-companyInfo'
48
				| 'commerce-customers'
49
				| 'commerce-disputes'
50
				| 'commerce-locations'
51
				| 'commerce-orders'
52
				| 'commerce-paymentMethods'
53
				| 'commerce-payments'
54
				| 'commerce-productCategories'
55
				| 'commerce-products'
56
				| 'commerce-taxComponents'
57
				| 'commerce-transactions'
58
			fetchOnFirstLink: false | true
59
			syncSchedule: number
60
			syncOrder: number
61
			syncFromUtc?: string
62
			syncFromWindow?: number
63
			monthsToSync?: number
64
			isLocked?: false | true
65
		}[]
66
		overridesDefaults: false | true
67
	}
68
) {
69
	const url = new URL(`https://api.codat.io/profile/syncSettings`)
70

71
	const response = await fetch(url, {
72
		method: 'POST',
73
		headers: {
74
			'Content-Type': 'application/json',
75
			Authorization: `Basic ${auth.encodedKey}`
76
		},
77
		body: JSON.stringify(body)
78
	})
79
	if (!response.ok) {
80
		const text = await response.text()
81
		throw new Error(`${response.status} ${text}`)
82
	}
83
	return await response.text()
84
}
85