Edits history of script submission #15343 for ' Update content template (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Update content template
     * Updates a content template. Note, blueprint templates cannot be updated
    via the REST API.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    'Admin' permission for the space to update a space template or 'Confluence Administrator'
    global permission to update a global template.
     */
    export async function main(
    	auth: Confluence,
    	body: {
    		templateId: string
    		name: string
    		templateType: 'page'
    		body: {
    			view?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			export_view?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			styled_view?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			storage?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			editor?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			editor2?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			wiki?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			atlas_doc_format?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    			anonymous_export_view?: {
    				value: string
    				representation:
    					| 'view'
    					| 'export_view'
    					| 'styled_view'
    					| 'storage'
    					| 'editor'
    					| 'editor2'
    					| 'anonymous_export_view'
    					| 'wiki'
    					| 'atlas_doc_format'
    					| 'plain'
    					| 'raw'
    			}
    		}
    		description?: string
    		labels?: { prefix: string; name: string; id: string; label: string }[]
    		space?: { key: string }
    	}
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/template`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago