Edits history of script submission #14194 for ' Get company report (bamboo_hr)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get company report
     * **Warning: This endpoint will soon be deprecated and replaced with Custom Reports - Get Report by ID.
     */
    export async function main(
    	auth: RT.BambooHr,
    	id: string,
    	format: string | undefined,
    	fd?: string | undefined,
    	onlyCurrent?: string | undefined,
    	AcceptHeaderParameter?: string
    ) {
    	const url = new URL(`https://${auth.companyDomain}.bamboohr.com/api/v1/reports/${id}`)
    	for (const [k, v] of [
    		['format', format],
    		['fd', fd],
    		['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