Edits history of script submission #15282 for ' Get label information (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Get label information
     * Returns label information and a list of contents associated with the label.
    
    **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
    Permission to access the Confluence site ('Can use' global permission). Only contents
    that the user is permitted to view is returned.
     */
    export async function main(
    	auth: Confluence,
    	name: string | undefined,
    	_type: 'page' | 'blogpost' | 'attachment' | 'page_template' | undefined,
    	start: string | undefined,
    	limit: string | undefined
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/label`)
    	for (const [k, v] of [
    		['name', name],
    		['type', _type],
    		['start', start],
    		['limit', limit]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	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