//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Create content template
* Creates a new content template. Note, blueprint templates cannot be created via the REST API.
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
'Admin' permission for the space to create a space template or 'Confluence Administrator'
global permission to create a global template.
*/
export async function main(
auth: Confluence,
body: {
name: string
templateType: string
body: {
view?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
export_view?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
styled_view?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
storage?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
editor?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
editor2?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
wiki?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
atlas_doc_format?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
anonymous_export_view?: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
}
description?: string
labels?: { prefix: string; name: string; id: string; label: string }[]
space?: { key: string }
}
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/template`)
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