Edits history of script submission #15616 for ' Retrieve policy validation templates (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Retrieve policy validation templates
     * Retrieves policy validation templates and policy types based on the provided countries. Policy types are unique.
     **Token scopes**: `time-off:read`
     */
    export async function main(auth: RT.Deel, countries: string | undefined) {
    	const url = new URL(`https://api.letsdeel.com/rest/v2/time_offs/policy-validation-templates`)
    	for (const [k, v] of [['countries', countries]]) {
    		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