Edits history of script submission #15617 for ' Retrieve restricted offboarding dates (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Retrieve restricted offboarding dates
     * Retrieves a list of dates, including weekends and public holidays, that are restricted for employee offboarding based on country-specific rules. Use this endpoint to plan employee offboarding by validating end-date selection. Call it when initiating an EOR offboarding flow to determine which dates are unavailable and what is the first day available.
     **Token scopes**: `contracts:read`
     */
    export async function main(
    	auth: RT.Deel,
    	contract_id: string,
    	termination_type?: 'TERMINATION' | 'RESIGNATION' | undefined
    ) {
    	const url = new URL(
    		`https://api.letsdeel.com/rest/v2/eor/contracts/${contract_id}/offboarding/restricted-dates`
    	)
    	for (const [k, v] of [['termination_type', termination_type]]) {
    		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