Edits history of script submission #15483 for ' Get an estimate of withholding amount given an equity event. (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get an estimate of withholding amount given an equity event.
     * Get an estimate of the withholding amount required as well as the assumptions behind the estimate, given a contract id, event amount and currency code.
     **Token scopes**: `contracts:read`, `global-payroll:read`
     */
    export async function main(
    	auth: RT.Deel,
    	contract_id: string,
    	event_value: string | undefined,
    	event_currency: string | undefined
    ) {
    	const url = new URL(
    		`https://api.letsdeel.com/rest/v2/contracts/${contract_id}/equity_withholding_estimate`
    	)
    	for (const [k, v] of [
    		['event_value', event_value],
    		['event_currency', event_currency]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago