How to have a html link update the data on an existing confluence page?
Asked by Shaw:

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


Answers:
author: Sven Schatter _Lively Apps_
body: To update a Confluence page you'll want to use the [Update content REST API](https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-put). To use the API you will either need to build a [Connect App](https://developer.atlassian.com/cloud/confluence/about-confluence-cloud/) or generate an [OAuth2 Token](https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/) for your existing app.

If you have questions about this you should post on the [Atlassian Developer Community](https://community.developer.atlassian.com/). :)

comments: author: Shaw
body: Thank you [@Sven Schatter _Lively Apps_](/t5/user/viewprofilepage/user-id/1169931) 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


author: Sven Schatter _Lively Apps_
body: 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](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](https://developer.atlassian.com/cloud/confluence/macros/) 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! :)


Tags: cloud