It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

8,368 views 6 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you