Edits history of script submission #15287 for ' Get macro body by macro ID (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Get macro body by macro ID
     * Returns the body of a macro in storage format, for the given macro ID.
     */
    export async function main(auth: Confluence, id: string, version: string, macroId: string) {
    	const url = new URL(
    		`https://${auth.domain}/wiki/rest/api/content/${id}/history/${version}/macro/id/${macroId}`
    	)
    
    	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