Edits history of script submission #10506 for ' searches fixed asset (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * searches fixed asset
     * By passing in the appropriate options, you can search for available fixed asset in the system
     */
    export async function main(
    	auth: Xero,
    	status: 'DRAFT' | 'REGISTERED' | 'DISPOSED' | undefined,
    	page: string | undefined,
    	pageSize: string | undefined,
    	orderBy:
    		| 'AssetType'
    		| 'AssetName'
    		| 'AssetNumber'
    		| 'PurchaseDate'
    		| 'PurchasePrice'
    		| 'DisposalDate'
    		| 'DisposalPrice'
    		| undefined,
    	sortDirection: 'asc' | 'desc' | undefined,
    	filterBy: string | undefined,
    	xero_tenant_id: string
    ) {
    	const url = new URL(`https://api.xero.com/assets.xro/1.0/Assets`)
    	for (const [k, v] of [
    		['status', status],
    		['page', page],
    		['pageSize', pageSize],
    		['orderBy', orderBy],
    		['sortDirection', sortDirection],
    		['filterBy', filterBy]
    	]) {
    		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