Edits history of script submission #15018 for ' Get categorized bank statement transactions (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Get categorized bank statement transactions
     * > **Available as beta release**
    >
    > This endpoint is part of a beta release. Please contact your account manager if you want to enable it.
    
    The *Get categorized bank statement transactions* endpoint returns fully categorized bank transactions for a company. Transaction data is obtained from the company's connected bank accounts.
    
    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,
    	page: string | undefined,
    	pageSize: string | undefined,
    	query: string | undefined,
    	orderBy: string | undefined
    ) {
    	const url = new URL(
    		`https://api.codat.io/companies/${companyId}/reports/categorizedBankStatement/${reportId}/transactions`
    	)
    	for (const [k, v] of [
    		['maxAge', maxAge],
    		['page', page],
    		['pageSize', pageSize],
    		['query', query],
    		['orderBy', orderBy]
    	]) {
    		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.json()
    }
    

    Submitted by hugo697 235 days ago