Edits history of script submission #14179 for ' Get Timesheet Entries (bamboo_hr)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get Timesheet Entries
     * Get all timesheet entries for a given period of time.
     */
    export async function main(
    	auth: RT.BambooHr,
    	start: string | undefined,
    	end: string | undefined,
    	employeeIds?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.companyDomain}.bamboohr.com/api/v1/time_tracking/timesheet_entries`
    	)
    	for (const [k, v] of [
    		['start', start],
    		['end', end],
    		['employeeIds', employeeIds]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			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