Edits history of script submission #14964 for ' Create source account (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Create source account
     * The _Create Source Account_ endpoint allows you to create a representation of a bank account within Codat's domain.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	connectionId: string,
    	body:
    		| {
    				id: string
    				accountName: string
    				accountType: 'checking' | 'savings' | 'loan' | 'creditCard' | 'prepaidCard'
    				accountNumber: string
    				routingInfo?: {
    					bankCode?: string
    					type?:
    						| 'rtn'
    						| 'aba'
    						| 'swift'
    						| 'bsb'
    						| 'iban'
    						| 'nz2'
    						| 'trno'
    						| 'sortcode'
    						| 'blz'
    						| 'ifsc'
    						| 'bankcode'
    						| 'apca'
    						| 'clabe'
    				}
    				sortCode?: string
    				currency: string
    				balance: number
    				modifiedDate?: string
    				accountInfo?: {
    					description?: string
    					nickname?: string
    					accountOpenDate?: string
    					availableBalance?: number
    				}
    		  }
    		| {
    				id: string
    				accountName?: string
    				accountType?: string
    				accountNumber?: string
    				sortCode?: string
    				currency?: string
    				balance?: number
    				modifiedDate?: string
    		  }
    ) {
    	const url = new URL(
    		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/connectionInfo/bankFeedAccounts`
    	)
    
    	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