Edits history of script submission #14955 for ' Create bank transactions (codat)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Codat = {
    	encodedKey: string
    }
    /**
     * Create bank transactions
     * The *Create bank transactions* endpoint creates new [bank transactions](https://docs.
     */
    export async function main(
    	auth: Codat,
    	companyId: string,
    	connectionId: string,
    	accountId: string,
    	timeoutInMinutes: string | undefined,
    	allowSyncOnPushComplete: string | undefined,
    	body: {
    		accountId: string
    		transactions: {
    			id: string
    			date: string
    			description?: string
    			counterparty?: string
    			reference?: string
    			reconciled?: false | true
    			amount: number
    			balance?: number
    			transactionType?:
    				| 'Unknown'
    				| 'Credit'
    				| 'Debit'
    				| 'Int'
    				| 'Div'
    				| 'Fee'
    				| 'SerChg'
    				| 'Dep'
    				| 'Atm'
    				| 'Pos'
    				| 'Xfer'
    				| 'Check'
    				| 'Payment'
    				| 'Cash'
    				| 'DirectDep'
    				| 'DirectDebit'
    				| 'RepeatPmt'
    				| 'Other'
    		}[]
    	}
    ) {
    	const url = new URL(
    		`https://api.codat.io/companies/${companyId}/connections/${connectionId}/push/bankAccounts/${accountId}/bankTransactions`
    	)
    	for (const [k, v] of [
    		['timeoutInMinutes', timeoutInMinutes],
    		['allowSyncOnPushComplete', allowSyncOnPushComplete]
    	]) {
    		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