Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to add special fields to a confluence page with Rest API - wiki

Liraz_Kenan March 1, 2020

Hey,

I am using the content/post api to create a new confluence page. It works just fine. Unfortunately the api doesn't support creating a new page out of an existing template.. I can easily create a content with headers and a table, and I know how to inject html content.

But the issue is: I didn't find any solution online to create more complex content. Specically: a date field (I want it to be presented the same way a date field is presented when you manually create it by '//' - it is presented as a formatted date, and if you edit the document - you can edit it through a "date picker" -choosing from a calendar).

Also I want to add "instructional text" field (this is the name when creating a template manually) - text that appears only on edit mode (some descriptions for each section, that don't appear on the doc it self, but do appear on edit - like a placeholder), and don't know how I can do it through the api.

My current json body (Which works fine for these simple types) is:

{
  body: {
    wiki: {
      representation: "wiki",
      value: "h1. some title name h1. another title ||tableCol||anothertablecol||.... {html}<somehtmltag />{html}"
    }
  }
}

How can I add a date field (date picker) and an instructional text, and perhaps more field types (creating a section, etc.. anything that I can do when creating a page manually). Didn't find any relevant real documentation for the wiki representation syntax.

Thanks in advance

1 answer

0 votes
Gareth Cantrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 1, 2020

Hi Leraz,

You will need to use the storage format instead of the wiki format to achieve the results you're after.

Storage format is an XHTML-based format used by Confluence internally; Placeholders such as what you're trying to achieve are represented using the following syntax:

<ac:placeholder>Your placeholder text here</ac:placeholder> 

and for date pickers, use:

<time datetime="yyyy-MM-dd"/> 

Once you have your templates in storage format, you can use the following JSON snippet to post the page content:

{
"body": {
"storage": {
"representation": "storage",
"value": "<h1>Introduction</h1>The following needs to be completed by <time datetime=\"2020-12-31\"/><br/><ac:placeholder>Add your own text here..</ac:placeholder>..."
}
}
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events