Edits history of script submission #15345 for ' Update space (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Update space
     * Updates the name, description, or homepage of a space.
    
    -   For security reasons, permissions cannot be updated via the API and
    must be changed via the user interface instead.
    -   Currently you cannot set space labels when updating a space.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    'Admin' permission for the space.
     */
    export async function main(
    	auth: Confluence,
    	spaceKey: string,
    	body: {
    		name?: string
    		description?: { plain: { value?: string; representation?: string } }
    		homepage?: {}
    		type?: string
    		status?: string
    	}
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/space/${spaceKey}`)
    
    	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