Edits history of script submission #15291 for ' Get multiple users using ids (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Get multiple users using ids
     * Returns user details for the ids provided in the request.
    Currently this API returns a maximum of 100 results.
    If more than 100 account ids are passed in, then the first 100 will be returned.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    Permission to access the Confluence site ('Can use' global permission).
     */
    export async function main(
    	auth: Confluence,
    	accountId: string | undefined,
    	expand: string | undefined
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/user/bulk`)
    	for (const [k, v] of [
    		['accountId', accountId],
    		['expand', expand]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    		},
    		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