Edits history of script submission #14983 for ' Download categorized bank statement Excel (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Download categorized bank statement Excel
     * > **Available as beta release**
    >
    > This endpoint is part of a beta release. Please contact your account manager if you want to enable it.
    
    Use the *Download categorized bank statement Excel* endpoint to download the categorized bank statement Excel file. 
    
    Before using it, you must call the [Generate report](https://docs.codat.io/lending-api#/operations/generate-report) endpoint of type `categorizedBankStatement`.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	reportId: string,
    	maxAge: string | undefined
    ) {
    	const url = new URL(
    		`https://api.codat.io/companies/${companyId}/reports/categorizedBankStatement/${reportId}/excel`
    	)
    	for (const [k, v] of [['maxAge', maxAge]]) {
    		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