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
Installing and using cURL
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:
REST API Examples
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 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:
String Comparison
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!
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
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
Found that this expand=body.storage in
Must be expand=body.export_view:
/rest/api/content/<contentID>?expand=body.export_view
Then value will contain HTML with result.
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
It looks like you're new here. Sign in or register to get started.