Edits history of script submission #14157 for ' Get Applications (bamboo_hr)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get Applications
     * Get a list of applications. The owner of the API key used must have access to ATS settings. Combine as many different optional parameter filters as you like.
     */
    export async function main(
    	auth: RT.BambooHr,
    	page?: string | undefined,
    	jobId?: string | undefined,
    	applicationStatusId?: string | undefined,
    	applicationStatus?: 'ALL' | 'ALL_ACTIVE' | 'NEW' | 'ACTIVE' | 'INACTIVE' | 'HIRED' | undefined,
    	jobStatusGroups?:
    		| 'ALL'
    		| 'DRAFT_AND_OPEN'
    		| 'Open'
    		| 'Filled'
    		| 'Draft'
    		| 'Deleted'
    		| 'On Hold'
    		| 'Canceled'
    		| undefined,
    	searchString?: string | undefined,
    	sortBy?:
    		| 'first_name'
    		| 'job_title'
    		| 'rating'
    		| 'phone'
    		| 'status'
    		| 'last_updated'
    		| 'created_date'
    		| undefined,
    	sortOrder?: 'ASC' | 'DESC' | undefined,
    	newSince?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.companyDomain}.bamboohr.com/api/v1/applicant_tracking/applications`
    	)
    	for (const [k, v] of [
    		['page', page],
    		['jobId', jobId],
    		['applicationStatusId', applicationStatusId],
    		['applicationStatus', applicationStatus],
    		['jobStatusGroups', jobStatusGroups],
    		['searchString', searchString],
    		['sortBy', sortBy],
    		['sortOrder', sortOrder],
    		['newSince', newSince]
    	]) {
    		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