Edits history of script submission #10228 for ' Get revenue by contacts report (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
    	token: string
    }
    /**
     * Get revenue by contacts report
     * The revenue by contact report provides a year to date profit and loss for customers and suppliers for a given organisation, including detailed contact information.
     */
    export async function main(
    	auth: Xero,
    	contactIds: string | undefined,
    	includeManualJournals: string | undefined,
    	startDate: string | undefined,
    	endDate: string | undefined,
    	xero_tenant_id: string
    ) {
    	const url = new URL(`https://api.xero.com/finance.xro/1.0/FinancialStatements/contacts/revenue`)
    	for (const [k, v] of [
    		['contactIds', contactIds],
    		['includeManualJournals', includeManualJournals],
    		['startDate', startDate],
    		['endDate', endDate]
    	]) {
    		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