Edits history of script submission #10219 for ' Get Bank Statement Accounting (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Get Bank Statement Accounting
     * For lenders that prefer using bank statement data as the source of truth.  We provide a data point that will allow access to customer bank statements, plus for reconciled bank transactions the matching accounting, invoice and billing data as well.  As customers reconcile bank statements to invoices and bills, this transaction detail will provide valuable insight for lender's assessment measures.
     */
    export async function main(
    	auth: Xero,
    	BankAccountID: string | undefined,
    	FromDate: string | undefined,
    	ToDate: string | undefined,
    	SummaryOnly: string | undefined,
    	xero_tenant_id: string
    ) {
    	const url = new URL(`https://api.xero.com/finance.xro/1.0/BankStatementsPlus/statements`)
    	for (const [k, v] of [
    		['BankAccountID', BankAccountID],
    		['FromDate', FromDate],
    		['ToDate', ToDate],
    		['SummaryOnly', SummaryOnly]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Accept: 'application/json',
    			'xero-tenant-id': xero_tenant_id,
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 515 days ago