Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to have a html link update the data on an existing confluence page?

Shaw November 2, 2019

I have a python code that's updating an existing confluence page with some data. I want to include a html link/button for users so that when they click this on confluence page it would trigger to make a call in the backend python code for  jenkins API for job build and update with the new data on confluence page. 

I know how to make API call using requests in python code for jenkins api and get the data but how can I hook this html link with python function that would trigger this api call? Is it possible ? Or do I have to use Ajax or something else?

Here is payload for my confluence API to update page where data is a var containing html string. 

payload = {'id': page_id, 'type': 'page', 'status': 'current', 'title': 'Report', 'space': {'key':'XXXX'}, 'ancestors':[{'id':parent_page_id}], 'body': {'storage': {'representation': 'storage', 'value': '<p><b>This page is auto-generated. In case you want manually update this page click </b><a href="url">here</a></p>' + data}}, 'version': {'number': existing_version, 'minorEdit': 'true'}}

 

1 answer

0 votes
Sven Schatter _Lively Apps_
Atlassian Partner
November 3, 2019

To update a Confluence page you'll want to use the Update content REST API. To use the API you will either need to build a Connect App or generate an OAuth2 Token for your existing app.

If you have questions about this you should post on the Atlassian Developer Community. :)

Shaw November 3, 2019

Thank you @Sven Schatter _Lively Apps_ for the reply . I understand that and I'm already using update content API to update with the static data being pulled from other apis and update here on an existing page. However, my question/query as per my post was regarding introducing a hyperlink and how to implement the action of hooking up this link to perform a POST of another api request that would get the data based upon whenever user clicks this link.

I'm getting the idea that I would have to use Ajax but not sure if there are any example one could point to for this case.

I can post on developer community as well. 

Thanks

Sven Schatter _Lively Apps_
Atlassian Partner
November 4, 2019

You could make a web server out of your python script and create a REST API that calls your existing code. So let's say if someone visits the URL https://your-python-server.com/rest/dosomething?pageId=123456&foo=bar your script will run and update the page with the id 123456. This link could then be embedded into a Confluence page. However this poses somewhat of a security risk as you would need to make your REST API available without authentication. That means everybody with the link could update your page, even if they don't have access to your site. It is also not very user friendly because the page id needs to be filled in on each page manually.

Generally it sounds more like you should build a macro using the Connect Framework. Using a macro you could execute an authenticated AJAX call to your server. The macro could also automatically pick up the page id of the current page and you could even present your functionality in the form of a shiny button instead of a boring link! :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events