Hello people.
I am trying to create Confluence page from Jira Issue Creation with post function.
I have code which works. my problem is that ,i want to create this page as a child page to an existing Page, which i created earlier.
def issueKey = 'PT-6'
def spaceKey = 'PT'
def result = get("/rest/api/3/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status != 200) {
return "Error retrieving issue ${result}"
}
```
def subtitle = "${result.body.key} - ${result.body.fields.summary}"
def pageContent = """<p>Document date:7/25/2019</p>
<ac:structured-macro ac:name='jira' ac:schema-version='1' ac:macro-id='ab120ae6-a585-4b2f-a713-4d23b355dc17'>
<ac:parameter ac:name='server'>System JIRA</ac:parameter>
<ac:parameter ac:name='columns'></ac:parameter>
<ac:parameter ac:name='serverId'>9cd10b67-ca88-369e-937a-42f902e4289b</ac:parameter>
<ac:parameter ac:name='key'>${issueKey}</ac:parameter>
</ac:structured-macro>"""
def parent = createconfluencePage("Initiation1", spaceKey)
createConfluencePage(subtitle, spaceKey, pageContent, parent)
String createConfluencePage(String pageTitle, String spaceKey, String pageContent, String parentPage) {
def params = [
type : "page",
title: pageTitle,
space: [
key: spaceKey
],
body : [
storage: [
value : pageContent.toString(),
representation: "storage"
]
]
]
if (parentPage != null) {
params["ancestors"] = [parentPage].collect { [id: parentPage.toString()] }
}
def pageResult = post('/wiki/rest/api/content')
.header('Content-Type', 'application/json')
.body(params)
.asObject(Map).body
if (pageResult.statusCode) {
logger.error("Failed to create a new page. Confluence responded with error code: {}", pageResult.statusCode)
} else {
logger.info("Successfully created a new space with id: {}", pageResult)
}
pageResult.id
}
parent
```
AS you see i need Page Link or id in
" def parent = createConfluencePage("Initiation1", spaceKey) "
How to get it?
Hi Dachi,
Thank you for your question.
I can confirm that ScriptRunner for Jira Cloud does not have any built-in functionality to auto get the ID of a page which means you will need to make a call to the Confluence Cloud Rest API in your script which is documented here in order to get the ID for the page you require.
You could then call the search API located here in order to search the page you require and to return it inside your script so that you can get the ID of it.
If you have created the page previously, then another approach you could look to use is to save the ID of the created page in a text field on your issue when the page is created, so that you can retrieve this value from the issue when it is needed in your script.
I hope this helps.
Regards,
Kristian
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.