Edits history of script submission #15513 for ' Get year to date payment for benefits 401k. (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Get year to date payment for benefits 401k.
     * Get year to date from employees from organization integrated with external benefits vendor
     **Token scopes**: `organizations:read`
     */
    export async function main(
    	auth: RT.Deel,
    	id: string,
    	date_start: string | undefined,
    	date_end: string | undefined
    ) {
    	const url = new URL(
    		`https://api.letsdeel.com/rest/v2/benefits/legal-entities/${id}/year-to-date-pay`
    	)
    	for (const [k, v] of [
    		['date_start', date_start],
    		['date_end', date_end]
    	]) {
    		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