Edits history of script submission #15315 for ' Publish legacy draft (confluence)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Confluence = {
    	email: string
    	apiToken: string
    	domain: string
    }
    /**
     * Publish legacy draft
     * Publishes a legacy draft of a page created from a blueprint.
     */
    export async function main(
    	auth: Confluence,
    	draftId: string,
    	status: string | undefined,
    	expand: string | undefined,
    	body: {
    		version: { number: number }
    		title: string
    		type: 'page'
    		status?: 'current'
    		space?: { key: string }
    		ancestors?: { id: string }[]
    	}
    ) {
    	const url = new URL(`https://${auth.domain}/wiki/rest/api/content/blueprint/instance/${draftId}`)
    	for (const [k, v] of [
    		['status', status],
    		['expand', expand]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	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