1 | |
2 | type Confluence = { |
3 | email: string |
4 | apiToken: string |
5 | domain: string |
6 | } |
7 | |
8 | * Update content template |
9 | * Updates a content template. Note, blueprint templates cannot be updated |
10 | via the REST API. |
11 |
|
12 | **[Permissions](https://confluence.atlassian.com/x/_AozKw) required**: |
13 | 'Admin' permission for the space to update a space template or 'Confluence Administrator' |
14 | global permission to update a global template. |
15 | */ |
16 | export async function main( |
17 | auth: Confluence, |
18 | body: { |
19 | templateId: string |
20 | name: string |
21 | templateType: 'page' |
22 | body: { |
23 | view?: { |
24 | value: string |
25 | representation: |
26 | | 'view' |
27 | | 'export_view' |
28 | | 'styled_view' |
29 | | 'storage' |
30 | | 'editor' |
31 | | 'editor2' |
32 | | 'anonymous_export_view' |
33 | | 'wiki' |
34 | | 'atlas_doc_format' |
35 | | 'plain' |
36 | | 'raw' |
37 | } |
38 | export_view?: { |
39 | value: string |
40 | representation: |
41 | | 'view' |
42 | | 'export_view' |
43 | | 'styled_view' |
44 | | 'storage' |
45 | | 'editor' |
46 | | 'editor2' |
47 | | 'anonymous_export_view' |
48 | | 'wiki' |
49 | | 'atlas_doc_format' |
50 | | 'plain' |
51 | | 'raw' |
52 | } |
53 | styled_view?: { |
54 | value: string |
55 | representation: |
56 | | 'view' |
57 | | 'export_view' |
58 | | 'styled_view' |
59 | | 'storage' |
60 | | 'editor' |
61 | | 'editor2' |
62 | | 'anonymous_export_view' |
63 | | 'wiki' |
64 | | 'atlas_doc_format' |
65 | | 'plain' |
66 | | 'raw' |
67 | } |
68 | storage?: { |
69 | value: string |
70 | representation: |
71 | | 'view' |
72 | | 'export_view' |
73 | | 'styled_view' |
74 | | 'storage' |
75 | | 'editor' |
76 | | 'editor2' |
77 | | 'anonymous_export_view' |
78 | | 'wiki' |
79 | | 'atlas_doc_format' |
80 | | 'plain' |
81 | | 'raw' |
82 | } |
83 | editor?: { |
84 | value: string |
85 | representation: |
86 | | 'view' |
87 | | 'export_view' |
88 | | 'styled_view' |
89 | | 'storage' |
90 | | 'editor' |
91 | | 'editor2' |
92 | | 'anonymous_export_view' |
93 | | 'wiki' |
94 | | 'atlas_doc_format' |
95 | | 'plain' |
96 | | 'raw' |
97 | } |
98 | editor2?: { |
99 | value: string |
100 | representation: |
101 | | 'view' |
102 | | 'export_view' |
103 | | 'styled_view' |
104 | | 'storage' |
105 | | 'editor' |
106 | | 'editor2' |
107 | | 'anonymous_export_view' |
108 | | 'wiki' |
109 | | 'atlas_doc_format' |
110 | | 'plain' |
111 | | 'raw' |
112 | } |
113 | wiki?: { |
114 | value: string |
115 | representation: |
116 | | 'view' |
117 | | 'export_view' |
118 | | 'styled_view' |
119 | | 'storage' |
120 | | 'editor' |
121 | | 'editor2' |
122 | | 'anonymous_export_view' |
123 | | 'wiki' |
124 | | 'atlas_doc_format' |
125 | | 'plain' |
126 | | 'raw' |
127 | } |
128 | atlas_doc_format?: { |
129 | value: string |
130 | representation: |
131 | | 'view' |
132 | | 'export_view' |
133 | | 'styled_view' |
134 | | 'storage' |
135 | | 'editor' |
136 | | 'editor2' |
137 | | 'anonymous_export_view' |
138 | | 'wiki' |
139 | | 'atlas_doc_format' |
140 | | 'plain' |
141 | | 'raw' |
142 | } |
143 | anonymous_export_view?: { |
144 | value: string |
145 | representation: |
146 | | 'view' |
147 | | 'export_view' |
148 | | 'styled_view' |
149 | | 'storage' |
150 | | 'editor' |
151 | | 'editor2' |
152 | | 'anonymous_export_view' |
153 | | 'wiki' |
154 | | 'atlas_doc_format' |
155 | | 'plain' |
156 | | 'raw' |
157 | } |
158 | } |
159 | description?: string |
160 | labels?: { prefix: string; name: string; id: string; label: string }[] |
161 | space?: { key: string } |
162 | } |
163 | ) { |
164 | const url = new URL(`https://${auth.domain}/wiki/rest/api/template`) |
165 |
|
166 | const response = await fetch(url, { |
167 | method: 'PUT', |
168 | headers: { |
169 | 'Content-Type': 'application/json', |
170 | Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`) |
171 | }, |
172 | body: JSON.stringify(body) |
173 | }) |
174 | if (!response.ok) { |
175 | const text = await response.text() |
176 | throw new Error(`${response.status} ${text}`) |
177 | } |
178 | return await response.json() |
179 | } |
180 |
|