//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Get content template
* Returns a content template. This includes information about template,
like the name, the space or blueprint that the template is in, the body
of the template, and more.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
'View' permission for the space to view space templates and permission to
access the Confluence site ('Can use' global permission) to view global templates.
*/
export async function main(
auth: Confluence,
contentTemplateId: string,
expand: string | undefined
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/template/${contentTemplateId}`)
for (const [k, v] of [['expand', expand]]) {
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