Posted on Leave a comment

Create a confluence page with REST API

Confluence can become a great tool when it is combined with other services that we use. In some cases tho you cannot find an available integration but there comes the rest api that you can use.

In this example we will automatically create a confluence page from another service using a rest API. In this example I was working on a custom confluence installation and not jira cloud. When using Jira Cloud the API can be different.

Using the link from confluence documentation you can locate any actions that you need to perform. Lets take as example the creation of a sub-page inside an existing page. You can find the curl API call below.

curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer TOKEN' -d '{"type":"page","title":"test incident","ancestors":[{"id":pageID}], "space":{"key":"dd"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}'


TOKEN: You should create a personal access token for a user with the rights to open/create/edit a page. You can use also username and password authentication with parameter -u user:password.
Title: the title of your new sub-page
Ancestors: The parent page under which to create a new page.
Space Key: your confluence space where you will create the page.
Body: you should keep the json format and pass the content you need to appear on the page body.
URL: you should use the url of the REST API. Just change the domain name and it will work on v7.18+

When we make the request we can see that a new page is created with the title that we provided.