0

Refresh data type

by
Published Oct 17, 2025

Refreshes a given data type for a given company. This is an asynchronous operation, and will bring updated data into Codat from the linked integration for you to view.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Refresh data type
7
 * Refreshes a given data type for a given company.
8

9
This is an asynchronous operation, and will bring updated data into Codat from the linked integration for you to view.
10
 */
11
export async function main(
12
	auth: Codat,
13
	companyId: string,
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
	connectionId: string | undefined
59
) {
60
	const url = new URL(`https://api.codat.io/companies/${companyId}/data/queue/${dataType}`)
61
	for (const [k, v] of [['connectionId', connectionId]]) {
62
		if (v !== undefined && v !== '' && k !== undefined) {
63
			url.searchParams.append(k, v)
64
		}
65
	}
66

67
	const response = await fetch(url, {
68
		method: 'POST',
69
		headers: {
70
			Authorization: `Basic ${auth.encodedKey}`
71
		},
72
		body: undefined
73
	})
74
	if (!response.ok) {
75
		const text = await response.text()
76
		throw new Error(`${response.status} ${text}`)
77
	}
78
	return await response.json()
79
}
80