Skip to main content
Example scripts
arrow icon
To homepage
Confluence
Cloud icon
Cloud

Create content template in Confluence Cloud

Created 8 month(s) ago, Updated 27 day(s) ago
App in script
ScriptRunner For Confluence
ScriptRunner For Confluence
by Adaptavist
Compatibility
compatibility bullet
Confluence
Language |
groovy
import com.atlassian.confluence.rest.clientv1.model.ContentTemplate

def templateName = "Page test Template"
def templateDescription = "The custom template description"

// Specify the body of the page in storage format - below is some example storage format.
def storageFormat = """<h1>A page created by ScriptRunner</h1>
                        <p>The first line of my page.</p>
                        <p>The second line of my page</p>"""

def body = [
        templateType: "page",
        name: templateName,
        description:templateDescription,
        body:[
                storage:[
                        value: storageFormat,
                        representation: "storage"
                ]
        ]
]

def response  = post('/wiki/rest/api/template')
        .header('Content-Type', 'application/json')
        .body(body)
        .asObject(ContentTemplate)
if (response.status != 200) {
    logger.error("Failed to create template.")
} else {
    logger.info("Successfully created template: {}", response.body.name)
}
Having an issue with this script?
Report it here