This article provides instructions for creating a solution that utilizes Jira Automation and the Confluence REST API to update a Confluence page with information from Jira issues.
For instance, When a label is added to a Jira issue, the label and the issue key should be added to an existing Confluence page.
The plan is as follows:
Get the page details using the REST API endpoint Get page by id.
Retrieve the page content and the page version.
Update the page using the REST API endpoint Update page. This Endpoint overwrites the existing page content. Therefore, we needed to retrieve the page content in Step 2.
Use this API endpoint Get pages to get the Confluence page id.
Or you can get the page id from the Confluence page:
Go to the ellipses (...) at the top-right of the page > Advanced Details > Page Information
Use this API endpoint Get page by id to get the page version.
Use Jira smart values to save the page version.
{{webResponse.body.version.number}}
Use this API endpoint Get page by id and append this parameter ?body-format=storage at the end of the URL to get the page content. Example:
https://<Cloud URL>/wiki/api/v2/pages/<Page ID>?body-format=storage
Use Jira smart values to save the page content.
{{webResponse.body.body.storage.value}}
Add a Field value changed trigger and select the labels field when a value is added.
Add a Send web request to get the page information and add the following information:
Web request URL: https://<Cloud URL>/wiki/api/v2/pages/<Page ID>?body-format=storage
Method: GET
Web request body: Empty
Select the checkbox: "Delay execution of subsequent rule actions until we've received a response for this web request"
Add the following headers:
Accept: application/json
Content-Type: application/json
Authorization: Basic <encoded Email:APIToken>
Add another Send web request to update the page and add the following information:
Web request URL: https://<Cloud URL>/wiki/api/v2/pages/<Page ID>
Method: PUT
Web request body: Custom data
{
"id": "<Page ID>", //pageID
"status": "current",
"title": "<Page Title>", //Pagetitle
"body": {
"representation": "storage",
"value": "{{webResponse.body.body.storage.value}}\n{{issue.key}} {{issue.labels}}" //Page current content + new content
},
"version": {
"number": "{{#=}}{{webResponse.body.version.number}} + 1{{/}}" //Increment page version
}
}
Add the following headers:
Accept: application/json
Content-Type: application/json
Authorization: Basic <encoded Email:APIToken> For more details on how to encode the credentials, please check this article: Automation for Jira - Send web request using Jira REST API
Thank you for reading and Happy Automation!
Hala ElRoumy
Jira Cloud Support Engineer
Atlassian
Amsterdam
4 accepted answers
19 comments