Edits history of script submission #15539 for ' List of people (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * List of people
     * Retrieve a list of People in your organization.
     **Token scopes**: `people:read`
     */
    export async function main(
    	auth: RT.Deel,
    	offset?: string | undefined,
    	limit?: string | undefined,
    	search?: string | undefined,
    	sort_by?:
    		| 'id'
    		| 'first_name'
    		| 'last_name'
    		| 'full_name'
    		| 'email'
    		| 'country'
    		| 'birth_date'
    		| 'hiring_type'
    		| 'start_date'
    		| 'team'
    		| 'job_title'
    		| 'hiring_status'
    		| 'completion_date'
    		| 'direct_manager'
    		| 'direct_reports_count'
    		| undefined,
    	sort_order?: 'asc' | 'desc' | undefined,
    	hiring_statuses?: string | undefined
    ) {
    	const url = new URL(`https://api.letsdeel.com/rest/v2/people`)
    	for (const [k, v] of [
    		['offset', offset],
    		['limit', limit],
    		['search', search],
    		['sort_by', sort_by],
    		['sort_order', sort_order],
    		['hiring_statuses', hiring_statuses]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		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