Edits history of script submission #9716 for ' Add members to group (actimo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Actimo = {
    	apiKey: string
    }
    
    export async function main(
    	auth: Actimo,
    	id: string,
    	overwriteGroups: string | undefined,
    	ignoreEmptyValues: string | undefined,
    	body: {
    		addr_city?: string
    		addr_country?: string
    		addr_line_1?: string
    		addr_line_2?: string
    		addr_state?: string
    		addr_zip?: string
    		company?: string
    		company_reg?: string
    		country_code?: string
    		data1?: string
    		data2?: string
    		data3?: string
    		department?: string
    		email?: string
    		employee_id?: number
    		first_name?: string
    		last_name?: string
    		manager_id?: number
    		manager_name?: string
    		manager_type?: string
    		phone_number?: string
    		timezone?: string
    		title?: string
    		'{data3-data20}'?: string
    	}[]
    ) {
    	const url = new URL(`https://actimo.com/api/v1/groups/${id}/members`)
    
    	for (const [k, v] of [
    		['overwriteGroups', overwriteGroups],
    		['ignoreEmptyValues', ignoreEmptyValues]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'api-key': auth.apiKey,
    			'Content-Type': 'application/json'
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    
    	return await response.json()
    }
    

    Submitted by hugo697 572 days ago