0

Get user

by
Published Oct 17, 2025

Returns a user. This includes information about the user, such as the display name, account ID, profile picture, and more. The information returned may be restricted by the user's profile visibility settings. **Note:** to add, edit, or delete users in your organization, see the user management REST API. **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: Permission to access the Confluence site ('Can use' global permission).

Script confluence
  • Submitted by hugo697 Bun
    Created 284 days ago
    1
    //native
    2
    type Confluence = {
    3
    	email: string
    4
    	apiToken: string
    5
    	domain: string
    6
    }
    7
    /**
    8
     * Get user
    9
     * Returns a user. This includes information about the user, such as the
    10
    display name, account ID, profile picture, and more. The information returned may be
    11
    restricted by the user's profile visibility settings.
    12
    
    
    13
    **Note:** to add, edit, or delete users in your organization, see the
    14
    user management REST API.
    15
    
    
    16
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    17
    Permission to access the Confluence site ('Can use' global permission).
    18
     */
    19
    export async function main(
    20
    	auth: Confluence,
    21
    	accountId: string | undefined,
    22
    	expand: string | undefined
    23
    ) {
    24
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/user`)
    25
    	for (const [k, v] of [
    26
    		['accountId', accountId],
    27
    		['expand', expand]
    28
    	]) {
    29
    		if (v !== undefined && v !== '' && k !== undefined) {
    30
    			url.searchParams.append(k, v)
    31
    		}
    32
    	}
    33
    	const response = await fetch(url, {
    34
    		method: 'GET',
    35
    		headers: {
    36
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    37
    		},
    38
    		body: undefined
    39
    	})
    40
    	if (!response.ok) {
    41
    		const text = await response.text()
    42
    		throw new Error(`${response.status} ${text}`)
    43
    	}
    44
    	return await response.json()
    45
    }
    46