Edits history of script submission #10233 for ' Retrieve all statements (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Retrieve all statements
     * By passing in parameters, you can search for matching statements
     */
    export async function main(
    	auth: Xero,
    	page: string | undefined,
    	pageSize: string | undefined,
    	Xero_Tenant_Id: string,
    	Xero_Application_Id: string,
    	Xero_User_Id: string
    ) {
    	const url = new URL(`https://api.xero.com/bankfeeds.xro/1.0/Statements`)
    	for (const [k, v] of [
    		['page', page],
    		['pageSize', pageSize]
    	]) {
    		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,
    			'Xero-Application-Id': Xero_Application_Id,
    			'Xero-User-Id': Xero_User_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