0

Sync new

by
Published Oct 17, 2025

Run a Commerce sync from the last successful sync up to the date provided (optional), otherwise UtcNow is used. If there was no previously successful sync, the start date in the config is used.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Sync new
7
 * Run a Commerce sync from the last successful sync up to the date provided (optional), otherwise UtcNow is used.
8
If there was no previously successful sync, the start date in the config is used.
9
 */
10
export async function main(auth: Codat, companyId: string, body: { syncTo?: string }) {
11
	const url = new URL(`https://api.codat.io/companies/${companyId}/sync/commerce/latest`)
12

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