0

Create content template

by
Published Oct 17, 2025

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.

Script confluence Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Confluence = {
3
	email: string
4
	apiToken: string
5
	domain: string
6
}
7
/**
8
 * Create content template
9
 * Creates a new content template. Note, blueprint templates cannot be created via the REST API.
10

11
**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:
12
'Admin' permission for the space to create a space template or 'Confluence Administrator'
13
global permission to create a global template.
14
 */
15
export async function main(
16
	auth: Confluence,
17
	body: {
18
		name: string
19
		templateType: string
20
		body: {
21
			view?: {
22
				value: string
23
				representation:
24
					| 'view'
25
					| 'export_view'
26
					| 'styled_view'
27
					| 'storage'
28
					| 'editor'
29
					| 'editor2'
30
					| 'anonymous_export_view'
31
					| 'wiki'
32
					| 'atlas_doc_format'
33
					| 'plain'
34
					| 'raw'
35
			}
36
			export_view?: {
37
				value: string
38
				representation:
39
					| 'view'
40
					| 'export_view'
41
					| 'styled_view'
42
					| 'storage'
43
					| 'editor'
44
					| 'editor2'
45
					| 'anonymous_export_view'
46
					| 'wiki'
47
					| 'atlas_doc_format'
48
					| 'plain'
49
					| 'raw'
50
			}
51
			styled_view?: {
52
				value: string
53
				representation:
54
					| 'view'
55
					| 'export_view'
56
					| 'styled_view'
57
					| 'storage'
58
					| 'editor'
59
					| 'editor2'
60
					| 'anonymous_export_view'
61
					| 'wiki'
62
					| 'atlas_doc_format'
63
					| 'plain'
64
					| 'raw'
65
			}
66
			storage?: {
67
				value: string
68
				representation:
69
					| 'view'
70
					| 'export_view'
71
					| 'styled_view'
72
					| 'storage'
73
					| 'editor'
74
					| 'editor2'
75
					| 'anonymous_export_view'
76
					| 'wiki'
77
					| 'atlas_doc_format'
78
					| 'plain'
79
					| 'raw'
80
			}
81
			editor?: {
82
				value: string
83
				representation:
84
					| 'view'
85
					| 'export_view'
86
					| 'styled_view'
87
					| 'storage'
88
					| 'editor'
89
					| 'editor2'
90
					| 'anonymous_export_view'
91
					| 'wiki'
92
					| 'atlas_doc_format'
93
					| 'plain'
94
					| 'raw'
95
			}
96
			editor2?: {
97
				value: string
98
				representation:
99
					| 'view'
100
					| 'export_view'
101
					| 'styled_view'
102
					| 'storage'
103
					| 'editor'
104
					| 'editor2'
105
					| 'anonymous_export_view'
106
					| 'wiki'
107
					| 'atlas_doc_format'
108
					| 'plain'
109
					| 'raw'
110
			}
111
			wiki?: {
112
				value: string
113
				representation:
114
					| 'view'
115
					| 'export_view'
116
					| 'styled_view'
117
					| 'storage'
118
					| 'editor'
119
					| 'editor2'
120
					| 'anonymous_export_view'
121
					| 'wiki'
122
					| 'atlas_doc_format'
123
					| 'plain'
124
					| 'raw'
125
			}
126
			atlas_doc_format?: {
127
				value: string
128
				representation:
129
					| 'view'
130
					| 'export_view'
131
					| 'styled_view'
132
					| 'storage'
133
					| 'editor'
134
					| 'editor2'
135
					| 'anonymous_export_view'
136
					| 'wiki'
137
					| 'atlas_doc_format'
138
					| 'plain'
139
					| 'raw'
140
			}
141
			anonymous_export_view?: {
142
				value: string
143
				representation:
144
					| 'view'
145
					| 'export_view'
146
					| 'styled_view'
147
					| 'storage'
148
					| 'editor'
149
					| 'editor2'
150
					| 'anonymous_export_view'
151
					| 'wiki'
152
					| 'atlas_doc_format'
153
					| 'plain'
154
					| 'raw'
155
			}
156
		}
157
		description?: string
158
		labels?: { prefix: string; name: string; id: string; label: string }[]
159
		space?: { key: string }
160
	}
161
) {
162
	const url = new URL(`https://${auth.domain}/wiki/rest/api/template`)
163

164
	const response = await fetch(url, {
165
		method: 'POST',
166
		headers: {
167
			'Content-Type': 'application/json',
168
			Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
169
		},
170
		body: JSON.stringify(body)
171
	})
172
	if (!response.ok) {
173
		const text = await response.text()
174
		throw new Error(`${response.status} ${text}`)
175
	}
176
	return await response.json()
177
}
178