Edits history of script submission #15622 for ' Return list of groups (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Return list of groups
     * List all the groups in your organization.
     **Token scopes**: `groups:read`
     */
    export async function main(
    	auth: RT.Deel,
    	limit?: string | undefined,
    	sort_order?: 'ASC' | 'DESC' | undefined,
    	cursor?: string | undefined,
    	include_archived_groups?: string | undefined,
    	external_metadata?: string | undefined
    ) {
    	const url = new URL(`https://api.letsdeel.com/rest/v2/groups`)
    	for (const [k, v] of [
    		['limit', limit],
    		['sort_order', sort_order],
    		['cursor', cursor],
    		['include_archived_groups', include_archived_groups],
    		['external_metadata', external_metadata]
    	]) {
    		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