Edits history of script submission #11128 for ' List all activity logs (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * List all activity logs
     * You can get a log of activities by all admins in an app.
     */
    export async function main(
    	auth: Intercom,
    	created_at_after: string | undefined,
    	created_at_before: string | undefined
    ) {
    	const url = new URL(`https://api.intercom.io/admins/activity_logs`)
    	for (const [k, v] of [
    		['created_at_after', created_at_after],
    		['created_at_before', created_at_before]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			'Intercom-Version': auth.apiVersion,
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 536 days ago