/* * "This script console script provides an example script for SR for Jira cloud of how to create a new page inside of Confluence from Jira Cloud * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner * license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed * or amended and must be included in any circumstances where the code snippet is shared by You or a third party." *///required importsimportorg.apache.commons.codec.binary.Base64;// Specify all the required parameters// Specify the id of the parent page that the new page will be created underdefparentPageId="<PageIDHere>"//Specify a title for the new pagedefpageTitle="<PageTitleHere>"// Specify the space key of the spcae that the new page will be created indefspaceKey="<PageDemoHere>"// Specify Credentials to access ConfluenceStringauthString="<UsernameHere>"+":"+"<PasswordHere>"byte[]authEncBytes=Base64.encodeBase64(authString.getBytes());StringauthStringEnc=newString(authEncBytes);// Specify the base url for the confluence instancedefconfluenceBaseURL="<ConfluenceBaseURLHere>"// Get values out of fields on the issuedefissueKey='<IssueKeyHere>'defissue=get('/rest/api/2/issue/'+issueKey).header('Content-Type','application/json').asObject(Map).bodydefsummary=issue.fields.summarydefdescription=issue.fields.description// Specify the field values obtained in the storage format for the pagedefstorageFormat="""${summary}<br/>${description.replaceAll('\n','<br/>')}"""// Specify the body of the rest requestdefbody=[type:"page",title:pageTitle,space:[key:spaceKey],ancestors:[[id:parentPageId]],body:[storage:[value:storageFormat,representation:"storage"]]]//create confluence (cloud) pagedefcreatePageResult=post("${confluenceBaseURL}/rest/api/content").header("Content-Type","application/json").header("Accept","application/json").header("Authorization","Basic ${authStringEnc}").body(body).asObject(Map)// Uncomment the code block below if you wish to add labels to the newly created page. /*def addLabels = post("${confluenceBaseURL}/rest/api/content/${createPageResult.body.id}/label") .header("Content-Type", "application/json") .header("Accept", "application/json") .header("Authorization", "Basic ${authStringEnc}") .body( [ // Note you can specify a comma seperated lists of strings here if you wish to add multiple labels to a page. // An example of adding more than 1 label is ""name" : "ALabel , label2", "name" : "<LabelNameHere>", "prefix": "global" ]) .asString()*/// Return the result of the created pagereturncreatePageResult
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.