0

Get long-running tasks

by
Published Oct 17, 2025

Returns information about all active long-running tasks (e.g. space export), such as how long each task has been running and the percentage of each task that has completed. **[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 long-running tasks
    9
     * Returns information about all active long-running tasks (e.g. space export),
    10
    such as how long each task has been running and the percentage of each task
    11
    that has completed.
    12
    
    
    13
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    14
    Permission to access the Confluence site ('Can use' global permission).
    15
     */
    16
    export async function main(
    17
    	auth: Confluence,
    18
    	key: string | undefined,
    19
    	start: string | undefined,
    20
    	limit: string | undefined
    21
    ) {
    22
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/longtask`)
    23
    	for (const [k, v] of [
    24
    		['key', key],
    25
    		['start', start],
    26
    		['limit', limit]
    27
    	]) {
    28
    		if (v !== undefined && v !== '' && k !== undefined) {
    29
    			url.searchParams.append(k, v)
    30
    		}
    31
    	}
    32
    	const response = await fetch(url, {
    33
    		method: 'GET',
    34
    		headers: {
    35
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    36
    		},
    37
    		body: undefined
    38
    	})
    39
    	if (!response.ok) {
    40
    		const text = await response.text()
    41
    		throw new Error(`${response.status} ${text}`)
    42
    	}
    43
    	return await response.json()
    44
    }
    45