It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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

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
Community showcase
Posted in Confluence

How is your team having fun and bonding, remotely, utilizing Confluence?

Thanks everyone for answering last week’s question. The winner of the random drawing from those who commented is: @LarryBrock I’ll contact you separately with your prize details. This wee...

283 views 9 7
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you