//native
type Codat = {
encodedKey: string
}
/**
* Download all files for a company
* 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.
*/
export async function main(auth: Codat, companyId: string, date: string | undefined) {
const url = new URL(`https://api.codat.io/companies/${companyId}/files/download`)
for (const [k, v] of [['date', date]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Basic ${auth.encodedKey}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.text()
}
Submitted by hugo697 235 days ago