Edits history of script submission #15262 for ' Get asynchronously converted content body from the id or the current status of the task. (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Get asynchronously converted content body from the id or the current status of the task.
     * Returns the asynchronous content body for the corresponding id if the task is complete 
    or returns the status of the task.
    
    After the task is completed, the result can be obtained for 5 minutes, or until an identical conversion request is made again,
    with allowCache query param set to false.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    If request specifies 'contentIdContext', 'View' permission for the space, and permission to view the content.
     */
    export async function main(auth: Confluence, id: string) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/contentbody/convert/async/${id}`)
    
    	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