Edits history of script submission #15540 for ' List of shifts (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * List of shifts
     * Retrieve a paginated list of shifts with details such as start and end times, breaks, metadata, and summary metrics. Supports pagination through `limit` and `offset` query parameters and filtering by `contractId`, date range (`fromDate` and `toDate`).
     **Token scopes**: `time-tracking:read`
     */
    export async function main(
    	auth: RT.Deel,
    	limit?: string | undefined,
    	offset?: string | undefined,
    	from_date?: string | undefined,
    	to_date?: string | undefined,
    	contract_id__?: string | undefined
    ) {
    	const url = new URL(`https://api.letsdeel.com/rest/v2/time_tracking/shifts`)
    	for (const [k, v] of [
    		['limit', limit],
    		['offset', offset],
    		['from_date', from_date],
    		['to_date', to_date],
    		['contract_id[]', contract_id__]
    	]) {
    		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