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 } }
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!
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哥
Updated. Thanks @Yong Yang!
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.
Hi @Yong Yang, thanks for that.
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.
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.
Thank You @Yong Yang, thanks for your comment.
Kind Regards, Vincenzo.
And @Yong Yang,
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.
key in (xx, xx)
Thank You very much @Yong Yang , very appreciated.
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.
{{webResponse.body.body.storage.value}}
Resolved:
https://community.atlassian.com/t5/Confluence-questions/Web-Request-GET-Get-Page-into-PUT-Update-Page-is-not-working/qaq-p/2728904
duplicated body? {{webResponse.body.body.storage.value}}
Please show us your payload so that we can identify how to write it
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.
Just use jsonEncode.
Hi @Anthony Nguyen,
how have you managed the Authorization Basic part?
I get Error 401.
Thanks, Vincenzo.
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/
@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:
Actions:
GET | https://<ourcompany>.atlassian.net/wiki/api/v2/pages/{{pageId}}?body-format=storage
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?
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/pagesHTTP method: POSTWeb request body: Custom dataCustom 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!
never mind! i found the solution.
@Ella Z If there's anything else, let me know
@Ella Z Could I perhaps trouble you for any additional details regarding the solution found, on that fateful day of August 16th?
Hello
I've been able to make the example work but the content of the page is only showing the issue key (which is useless for me).
If I try to add the description of the issue to the Confluence page like this:
{ "id": "<Page ID>", //pageID "status": "current", "title": "<Page Title>", //Pagetitle "body": { "representation": "storage", "value": "{{webResponse.body.body.storage.value}}\n{{issue.description}} {{issue.labels}}" //Page current content + new content }, "version": { "number": "{{#=}}{{webResponse.body.version.number}} + 1{{/}}" //Increment page version } }
Then I have an error:
Error found in the HTTP body response:{"errors":[{"status":400,"code":"INVALID_MESSAGE","title":"Invalid message","detail":null}]}
What am I doing wrong?
Any help would be appreciated.
KiM
Hi @Kim Serradell -- Welcome to the Atlassian Community!
First thing, this is a very old article / thread, so it may help to create a new question and perhaps add a link back to the article. That will ensure the maximum number of people see it to offer suggestions.
Until that new question is created...
Depending upon the contents of your Description field, it may be producing an invalid JSON expression. Perhaps try adding encoding to the field to help:
{{issue.description.jsonEncode}}
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#Json-encoding
Kind regards,Bill
This is super useful - great document and thanks for sharing!
Thanks for your input @Bill Sheboy
Unfortunately, I did not work.
I will try to reach Atlassian Support.
Hi @Kim Serradell, I'm happy to see you found this article helpful. I see Bill has already suggested a good solution. To look further into the rule and help debug it, please contact our support and I would be happy to assist you! Thanks,Hala
Thank you @Chris.Parkes for your feedback! I'm happy that you found it useful!
Hi @Hala ElRoumy can you help me on my use case wherein what I want to happen is if a ticket is created it should create a new row on the table on the page but what it's. doing is just overwriting the exisiting entry.Here's a snippet of my PUT function:
Hi @Danisse
I got it to work by using this JSON in the value:
"value": "{{webResponse.body.body.storage.value.substringBefore("</tbody></table>").jsonEncode}}<tr><td>{{issue.key}}</td><td>{{issue.summary}}</td><td>{{issue.assignee.displayName}}</td><td>{{issue.created}}</td></tr></tbody></table>"
So basically, I extracted the part of the table before the table tags and then I added the new row and then closed the table tag and it worked!
Give it a try and let me know
Hi @Hala ElRoumy @Yong Yang
This (API calls to confluence) is new for me and I haven't tried much yet. I'm looking to do something similar, but I imagine slightly more complex than in this post.
I saw this comment in this threat:
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.
However, I do need to use API/Automation to make happen what I want, so this answer doesn't work for me.
I'm looking to update a specific part of a page, not redo the entire page or (as mentioned above) add another row to a page. I'd also prefer to have my own table or layout, not the limited one from the macro's.I'm looking to update information from Assets onto a Confluence page for people who don't (always) have a JSM license. Because of this, the Assets-macro doesn't work for me as the users will get a no permission-block. Even if they did, the Assets-macro doesn't allow for much tweaking or one long list (it becomes a slide within the frame).
When products/admins (as attributes) of the team (the main object) are updated, I'd like the automation to send this update, from the assets to the Confluence page. I'll try to recreate a part of such a table below:'Before the update in the asset and the API sends the information':
'After the API sends the information to Confluence', where team 2 has added an admin (admin 7).
Product
Basically meaning that there needs to be an API that update's that specific cell when that specific team-object has been updated.I already have automations with API's working to allow team-admins to add/remove information to their assets, but I need that information nicely structured in (possible public) confluence pages. So it would be great if I could add to those automations with additional API's that make sure that updated information is also send to those 'cells'.
Hopefully this is somewhat understandable, and hopefully you see a way you could help me with this!
2024 is an 'old' article? Have you searched in the Community Forums much??
Any input on this error would be helpful:
The call:
"status": "current","version": {"number":{{#=}}{{webResponse.body.version.number}}+1{{/}}},"title": "Engage Defects {{now.convertToTimeZone("America/Chicago").format("MM/dd/yyyy")}}","body":{"value":"{{webResponse.body.body.storage.value.JsonString||Key||Summary||Status||Updated||\n{{#lookupIssues}}|{{key}}|{{summary}}|{{status.name}}|{{updated.format("MM/dd/yyyy")}}|\n{{/}}","representation":"wiki"}
If I remove the ".JsonString", the error changes to:
I have also tried changing the representation to "storage" instead of "wiki" and tried "\\n" just in case. Same 'Illegal unquoted character' error.
Found jsonEncode and got it to resolve my issues (i.e. {{webResponse.body.body.storage.value.jsonEncode}}) then was pointed to this too: https://community.atlassian.com/forums/Confluence-questions/Web-Request-GET-Get-Page-into-PUT-Update-Page-is-not-working/qaq-p/2728904
Also see: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#jsonEncode--
https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/
It looks like you're new here. Sign in or register to get started.