0

Get anonymous user

by
Published Oct 17, 2025

Returns information about how anonymous users are represented, like the profile picture and display name. **[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 anonymous user
    9
     * Returns information about how anonymous users are represented, like the
    10
    profile picture and display name.
    11
    
    
    12
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    13
    Permission to access the Confluence site ('Can use' global permission).
    14
     */
    15
    export async function main(auth: Confluence, expand: string | undefined) {
    16
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/user/anonymous`)
    17
    	for (const [k, v] of [['expand', expand]]) {
    18
    		if (v !== undefined && v !== '' && k !== undefined) {
    19
    			url.searchParams.append(k, v)
    20
    		}
    21
    	}
    22
    	const response = await fetch(url, {
    23
    		method: 'GET',
    24
    		headers: {
    25
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    26
    		},
    27
    		body: undefined
    28
    	})
    29
    	if (!response.ok) {
    30
    		const text = await response.text()
    31
    		throw new Error(`${response.status} ${text}`)
    32
    	}
    33
    	return await response.json()
    34
    }
    35