I've been asked to try and write a script to synchronise tasks between Confluence and Google. However, I can't find an API to read and/or write tasks in Confluence. Is there one?
Thanks.
Hello there Philip!
You sure can do this with Confluence REST API. For this to work we need to send a curl with the necessary content into your instance. For example:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"MY TASK PAGE","space":{"key":"CIAS"},"body":{"storage":{"value":"<p>This is a new page</p> <ac:task-list><ac:task><ac:task-status>incomplete</ac:task-status><ac:task-body>task list item</ac:task-body></ac:task></ac:task-list>","representation":"storage"}}}' http://yourconfluence.address/rest/api/content/ | python -mjson.tool
This is the resulting page after sending this curl to my local Confluence instance:
You need to run this curl command from a terminal, either Linux or macOS. This also works with Windows but you will need to install some software before being able to.
For further information on curl, you can check here:
How to cURL POST from the Command Line
15 Tips On How to Use ‘Curl’ Command in Linux
What happens here is that you are POSTing to the server the page body as storage format string. With storage format, you can create structures using a simple syntax:
Confluence Storage Format - Lists
There is much more that you can do with REST API! You can check some working examples here:
Knowing that, it is now a matter of choosing how you want to trigger this curl when tasks are added/removed.
Let us know if this does help your objective!
Hi Diego
Thanks for this. It helps me understand how to add a task to an existing page but, unfortunately, it doesn't help me with retrieving tasks from Confluence.
I was hoping that since there is a My Tasks page (which clearly does have a way of pulling all of the tasks together) that there might be a programmatic way of achieving that outcome.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello there Philip!
You can also retrieve the page contents with REST API. The cURL needed would look like this:
curl -u admin:admin http://yourinstance.address/wiki/rest/api/content/<contentID>?expand=body.storage | python -mjson.tool
You can check more information about REST API here:
REST API Examples - Read content, and expand the body
You could set a cron job that calls the cURL to read a page content and then trigger another job to call the cURL to update said page.
How to Schedule tasks on Linux
The trickier part is when we need to compare both pages, from Google and Confluence. We can do that in Linux by comparing the Strings:
After you compare them, you can send the results to a variable and use it with the cURL to update the page. Much like how a payload would work.
Also, I would like to clarify that the page named MY TASK PAGE was set just as a placeholder in my last example.
Hope this helps out!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Diego
I appreciate that … although that would require me to scan every page in every space, something that the My Tasks page doesn't seem to need to do.
I will take it, therefore, that there isn't a cleaner way to retrieve tasks for an individual.
Thanks for the assistance.
Regards
Philip
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, this requires you to scan for every page that has tasks in it. However, each time you publish a page, a new database entry is generated in the CONTENT table in Confluence. Each entry has a different contentid value.
So, if you end up editing one of those pages with tasks, you will need to get their contentid again. But, as long as you keep the page name unique to your entire instance, you should be able to find it relatively easily by querying the database and matching the lowertitle column.
We have a similar situation where a customer needed to find a specific page version but the query should help you to build yours for this case:
Get required version of content properties via REST API
But yes, you are right. There is no real "clean" way of doing this. No native method or API is currently capable of doing this kind of integration and comparisons.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Philip Colmer
FYI, I also need the API to read the task list and I got the answer form here https://community.atlassian.com/t5/Confluence-questions/Listing-user-tasks-through-REST-API-doesnt-always-work/qaq-p/1459293?utm_source=dm&utm_medium=unpaid-social&utm_campaign=P:online*O:community*I:social_share
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have same issue - can't get task list via API.
@Diego I've tried your advice, but it doesn't help me. Details follows.
As you said, I've created a page with macro on it. I've done it manually via web-ui (browser), not REST API but I think it does not matter, because when I access this page via web-ui - it shows me a list of all inline tasks - i.e. works as expected.
But when I request this page via REST API as you said
/rest/api/content/<contentID>?expand=body.storage
it respond with
{
"id": "60265808",
"type": "page",
"status": "current",
"title": "tasks all",
"body": {
"storage": {
"value": "<p><ac:placeholder>Edit the Task Report macro to customise your report.</ac:placeholder></p><p><ac:structured-macro ac:name=\"tasks-report-macro\" ac:schema-version=\"1\" ac:macro-id=\"fdd20554-fe0a-424f-9a52-53fd7a6b8bbf\"><ac:parameter ac:name=\"reverseSort\">true</ac:parameter><ac:parameter ac:name=\"status\">complete</ac:parameter></ac:structured-macro></p>",
"representation": "storage",
"_expandable": {
"content": "/rest/api/content/60265808"
}
},
//...
i.e. - It returns macro markup, but not the result of its execution!
So how do i get inline tasks list?
For other who have same issue:
Please vote for feature request CONFSERVER-56023: REST API for inline-tasks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found that this expand=body.storage in
/rest/api/content/<contentID>?expand=body.storage
Must be expand=body.export_view:
/rest/api/content/<contentID>?expand=body.export_view
Then value will contain HTML with result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.