Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Jira Automation: Updating a Confluence page with information from Jira issues

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.

Solution

The plan is as follows:

  1. Get the page details using the REST API endpoint Get page by id.

  2. Retrieve the page content and the page version.

  3. 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.

Get Page ID

  • 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

Get the version number

  • 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}}

Get the page content

  • 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}}


Build the automation rule

  1. Add a Field value changed trigger and select the labels field when a value is added.

  2. 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>
        GETpageinfo.png

 

  1. 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:

19 comments

YY Brother
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 3, 2024

 Hi @Hala ElRoumy 

Thanks for your sharing.

Automation for Jira (A4J) is a Jira App, which was acquired by Atlassian. And the rebradning name is Jira Automaiton, I think.

Thanks,

YY哥

Like Hala ElRoumy likes this
Hala ElRoumy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 4, 2024

Updated. Thanks @YY Brother

Like YY Brother likes this
vincenzo_spatafora
Contributor
June 10, 2024

Hi @Hala ElRoumy, thanks for sharing that.

What about the case where you need to edit/update (PUT) a specific cell of a table which is in Confluence?

See please attached file showing the table where I would like my automation rule is update the status of the JIra tickets (as their transition changes).

Thanks in advance, Vincenzo.

Table_in_Confluence.PNG

vincenzo_spatafora
Contributor
June 10, 2024

Hi @YY Brother, thanks for that.

What about the case where you need to edit/update (PUT) a specific cell of a table which is in Confluence?

See please attached file showing the table where I would like my Jira automation rule to update the status of the JIra tickets (as their transition changes).

I use Jira DC version 9.12.5.

Thanks in advance, Vincenzo.

 

YY Brother
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 10, 2024

Hi @vincenzo_spatafora 

About jira issue status update in confluence page, if you insert jira issue macro into the page, the jira issues' status will change accordingly in the confluence page (refresh) once jira issue's status is transitioned. 

I don't for your scenario, it seems we don't need automation.

Like vincenzo_spatafora likes this
vincenzo_spatafora
Contributor
June 10, 2024

Thank You @YY Brother, thanks for your comment.

Kind Regards, Vincenzo. 

Like YY Brother likes this
vincenzo_spatafora
Contributor
June 10, 2024

And @YY Brother

would you know the syntax to add 2 (or 3) issues key in the confluence macro?

I have tried the follwoing but it doesn't work; it picks alwasy the first issue key.

Thanks in advance, Vincenzo.

Confluence_Macro.PNG

 

YY Brother
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 10, 2024

key in (xx,  xx)

Like vincenzo_spatafora likes this
vincenzo_spatafora
Contributor
June 10, 2024

Thank You very much @YY Brother , very appreciated.

Kind Regards, Vincenzo.

Anthony Nguyen
Contributor
June 17, 2024

Doesn't work for me, unfortunately.

Sending {{webResponse.body.body.storage.value}} back in during step 3 causes error for me if it is anything other than simple text.


Resolved: 

https://community.atlassian.com/t5/Confluence-questions/Web-Request-GET-Get-Page-into-PUT-Update-Page-is-not-working/qaq-p/2728904

YY Brother
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2024

duplicated body? {{webResponse.body.body.storage.value}}

Please show us your payload so that we can identify how to write it

Anthony Nguyen
Contributor
June 17, 2024

Thank you, I figured out the mistake. If {{...value}} contains any elements like smart link, the unescaped " in them causes an issue when trying to use it again for update. I believe I resolved it by doing {{...value.replace("\"", "\\\"")}}. I'll add a link to my question to my original comment.

Like YY Brother likes this
vincenzo_spatafora
Contributor
June 19, 2024

Hi @Anthony Nguyen,

how have you managed the Authorization Basic part?

I get Error 401.

Thanks, Vincenzo. 

Carl Pritchett June 24, 2024

For 401, you need to ensure you are using the Authorization header with the value

Basic <base64 encoded email_Address:api-key>

See this article https://developer.atlassian.com/cloud/confluence/basic-auth-for-rest-apis/

Like # people like this
Juan D’Achiardi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 5, 2024

@Hala ElRoumy thank you so much for sharing this. It's exactly what I need. However, I am getting a 404 response on the web requests. What I am doing in my automation is: 

Trigger:

  • When a version is released

Actions:

  • Transition issues tagged with that fixVersion to Deployed
  • Create a page in Confluence
  • Store a variable with the created page id {{pageId}}
  • Log the {{pageId}} variable
  • Using the stored value, retrieve the content of the created page via the confluence API  
    • GET | https://<ourcompany>.atlassian.net/wiki/api/v2/pages/{{pageId}}?body-format=storage

  • Store a variable with the part of the response that I need {{content}}
  • Modify the {{content}} and store as {{updatedContent}}
  • Using the new value, update the page
    • PUT | https://<ourcompany>.atlassian.net/wiki/api/v2/pages/{{pageId}} with custom data in the request body

Unfortunately, for both the requests GET and PUT, I am getting 404s. When I try to run manually on terminal or postman, it works fine.

Do you have any ideas or can you see what I am doing wrong?

Hala ElRoumy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 5, 2024

Hi @Juan D’Achiardi , You are welcome. I'm glad the post was helpful.

If you are creating a new page and not updating an existing one, you can just use the Create page endpoint and add the content you want to the page body in the same request.

Example:

Use the API endpoint Create page with the following configuration:
Web request URL: https://<Site Cloud URL>/wiki/api/v2/pages
HTTP method: POST
Web request body: Custom data
Custom data:

{
  "spaceId": "<SPACEID from Confluence>",
  "title": "<Title has to be unique>",
  "body": {
    "representation": "storage",
    "value": "<The content you want>"
  }
}

How to get the space ID? 
Run this API in the browser:
https://<Site Cloud URL>/wiki/rest/api/space/<SPACE KEY>

Can you please try it out and share a screenshot of the rule? Thanks!

Ella Z
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2024

never mind! i found the solution.

Like Hala ElRoumy likes this
Hala ElRoumy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 16, 2024

@Ella Z If there's anything else, let me know ;) 

Jason M.
Contributor
September 14, 2024

@Ella Z Could I perhaps trouble you for any additional details regarding the solution found, on that fateful day of August 16th? 

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events