Edits history of script submission #15070 for ' Get invoice attachment (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Get invoice attachment
     * The *Get invoice attachment* endpoint returns 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}`
    	)
    
    	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.json()
    }
    

    Submitted by hugo697 235 days ago