//native
type Codat = {
encodedKey: string
}
/**
* Download bill attachment
* The *Download bill attachment* endpoint downloads a specific attachment for a given `billId` and `attachmentId`.
[Bills](https://docs.codat.io/sync-for-payables-api#/schemas/Bill) are invoices that represent the SMB's financial obligations to their supplier for a purchase of goods or services.
Check out our [coverage explorer](https://knowledge.codat.io/supported-features/accounting?view=tab-by-data-type&dataType=bills) for integrations that support downloading a bill attachment.
*/
export async function main(
auth: Codat,
companyId: string,
connectionId: string,
billId: string,
attachmentId: string
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/connections/${connectionId}/data/bills/${billId}/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