Edits history of script submission #14151 for ' Estimate Future Time Off Balances (bamboo_hr)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Estimate Future Time Off Balances
     * This endpoint will sum future time off accruals, scheduled time off, and carry-over events to produce estimates for the anticipated time off balance on a given date in the future.
     */
    export async function main(
    	auth: RT.BambooHr,
    	employeeId: string,
    	end: string | undefined,
    	AcceptHeaderParameter?: string
    ) {
    	const url = new URL(
    		`https://${auth.companyDomain}.bamboohr.com/api/v1/employees/${employeeId}/time_off/calculator`
    	)
    	for (const [k, v] of [['end', end]]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			...(AcceptHeaderParameter ? { AcceptHeaderParameter: AcceptHeaderParameter } : {}),
    			Authorization: 'Basic ' + btoa(`${auth.apiKey}:x`)
    		},
    		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