Edits history of script submission #14162 for ' Get Employee (bamboo_hr)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get Employee
     * Get employee data by specifying a set of fields. This is suitable for getting basic employee information, including current values for fields that are part of a historical table, like job title, or compensation information. See the [fields](ref:metadata-get-a-list-of-fields) endpoint for a list of possible fields.
     */
    export async function main(
    	auth: RT.BambooHr,
    	id: string = '0',
    	fields: string | undefined,
    	onlyCurrent?: string | undefined,
    	AcceptHeaderParameter?: string
    ) {
    	const url = new URL(`https://${auth.companyDomain}.bamboohr.com/api/v1/employees/${id}`)
    	for (const [k, v] of [
    		['fields', fields],
    		['onlyCurrent', onlyCurrent]
    	]) {
    		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