Edits history of script submission #14953 for ' Create bank account (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Create bank account
     * The *Create bank account* endpoint creates a new [bank account](https://docs.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	connectionId: string,
    	timeoutInMinutes: string | undefined,
    	body: {
    		accountName?: string
    		accountType?: 'Unknown' | 'Credit' | 'Debit'
    		nominalCode?: string
    		sortCode?: string
    		accountNumber?: string
    		iBan?: string
    		currency?: string
    		balance?: number
    		institution?: string
    		availableBalance?: number
    		overdraftLimit?: number
    		status?: 'Unknown' | 'Active' | 'Archived' | 'Pending'
    	}
    ) {
    	const url = new URL(
    		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/push/bankAccounts`
    	)
    	for (const [k, v] of [['timeoutInMinutes', timeoutInMinutes]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: `Basic ${auth.encodedKey}`
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago