0

Download all files for a company

by
Published Oct 17, 2025

The *Download files* endpoint downloads all files that have been uploaded by to SMB to Codat. A `date` may be specified to download any files uploaded on the date provided.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Download all files for a company
7
 * The *Download files* endpoint downloads all files that have  been uploaded by to SMB to Codat. A `date` may be specified to download any files uploaded on the date provided.
8
 */
9
export async function main(auth: Codat, companyId: string, date: string | undefined) {
10
	const url = new URL(`https://api.codat.io/companies/${companyId}/files/download`)
11
	for (const [k, v] of [['date', date]]) {
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.text()
29
}
30