//native
type Codat = {
encodedKey: string
}
/**
* Download invoice attachment
* The *Download invoice attachment* endpoint downloads a specific attachment for a given `invoiceId` and `attachmentId`.
[Invoices](https://docs.codat.io/lending-api#/schemas/Invoice) are itemized records of goods sold or services provided to a customer.
*/
export async function main(
auth: Codat,
companyId: string,
connectionId: string,
invoiceId: string,
attachmentId: string
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/connections/${connectionId}/data/invoices/${invoiceId}/attachments/${attachmentId}/download`
)
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