Edits history of script submission #9278 for ' Update User (motimate)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Motimate = {
    	token: string
    }
    
    export async function main(
    	auth: Motimate,
    	user_id: string,
    	identifier_type: 'id' | 'external_id' | undefined,
    	body: {
    		external_id?: string
    		email?: string
    		first_name?: string
    		last_name?: string
    		phone_number?: string
    		imported?: false | true
    		organization_role?:
    			| 'chief_editor'
    			| 'normal_user'
    			| 'organization_admin'
    			| 'pulse_editor'
    			| 'training_editor'
    		preferred_language?:
    			| 'cs'
    			| 'da'
    			| 'de'
    			| 'en'
    			| 'es'
    			| 'fi'
    			| 'fr'
    			| 'hr'
    			| 'hu'
    			| 'it'
    			| 'lt'
    			| 'lv'
    			| 'nb'
    			| 'nl'
    			| 'nn'
    			| 'pl'
    			| 'pt'
    			| 'ro'
    			| 'ru'
    			| 'se'
    			| 'sq'
    			| 'sr'
    			| 'sv'
    			| 'tr'
    		status?: 'active' | 'inactive' | 'manually_activated' | 'manually_deactivated'
    	}
    ) {
    	const url = new URL(`https://motimateapp.com/public_api/users/${user_id}`)
    
    	for (const [k, v] of [['identifier_type', identifier_type]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.token
    		},
    		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 581 days ago