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

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Get categorized bank statement
     * > **Categorization engine**
    >
    > The categorization engine uses machine learning and has been fully trained against Plaid and TrueLayer banking data sources. It is not fully trained against the Basiq banking data source.
    
    The _Get categorized bank statement_ endpoint provides a fully categorized list of banking transactions for a company. Accounts and transaction data are obtained from the company's banking data sources.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	page: string | undefined,
    	pageSize: string | undefined,
    	query: string | undefined
    ) {
    	const url = new URL(
    		`https://api.codat.io/companies/${companyId}/reports/enhancedCashFlow/transactions`
    	)
    	for (const [k, v] of [
    		['page', page],
    		['pageSize', pageSize],
    		['query', query]
    	]) {
    		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