Edits history of script submission #15225 for ' Add labels to content (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Add labels to content
     * Adds labels to a piece of content. Does not modify the existing labels.
    
    Notes:
    
    - Labels can also be added when creating content ([Create content](#api-content-post)).
    - Labels can be updated when updating content ([Update content](#api-content-id-put)).
    This will delete the existing labels and replace them with the labels in
    the request.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    Permission to update the content.
     */
    export async function main(
    	auth: Confluence,
    	id: string,
    	body: { prefix: string; name: string }[] | { prefix: string; name: string }
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/${id}/label`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		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