Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,673
Community Members
 
Community Events
168
Community Groups

Create pages via the REST API as creating manually

I have the following use case: we use Confluence to document in a specific format the way work is carried out in Jira issues.
In this sense, the Confluence page will more or less contain the same description as the Jira issue.

 

Right now, we are doing this manually. Whenever I copy content from the Description field of a Jira issue (not while editing it) and I paste it in the Confluence page, the markups are in place and I see the content in Confluence as it is in Jira.

But I want to automate this process, with a webhook sending the issue details to a service which then creates a Confluence page via the REST API, which should contain the same content as the issue Description (an automatic copy-paste, if you want). But, when creating the page via the API, the markup is saved as pure text.

How should I set the body and representation types so that I get the same behaviour and view when using the REST API?

For example, when I copy paste manually, I get this:

----------------------

This issue is created in order to test Bug creation --> Jira Automation --> AWS Lambda --> Confluence API --> AWS Lambda --> Jira API functionality for automatically creating a Confluence page and linking it to the created Bug.

Here is a link to Google dot com, to test it
And here is a user mention: [redacted]

{
"keyString":"this is a JSON formatted piece of code",
"keyInteger": 1234,
"keyObject": {"innerKey": true}
}

This text is preformatted
And here's a picture of a cat, bullet cat:
bullet_cat.jpg

------------------------

 

But when I create the page via the API, I get this:

----------------------

<at:declarations /><h1>1 - Problem description</h1><p>This issue is created in order to test Bug creation --> Jira Automation --> AWS Lambda --> Confluence API --> AWS Lambda --> Jira APIfunctionality for automatically creating a Confluence page and linking it to the created Bug.

Here is a link to Google dot com, to test it
And here is a user mention: [redacted]

Error rendering macro 'code': Invalid value specified for parameter 'lang'

{
"keyString":"this is a JSON formatted piece of code",
"keyInteger": 1234,
"keyObject": {"innerKey": true}
}

This text is preformatted
And here's a picture of a cat, bullet cat:

----------------------

 

The REST API reference should better explain the body types and representation values for when creating pages via the API. 

3 answers

1 accepted

2 votes
Answer accepted

You have to first convert the content by accessing [1], before creating the page with the content. Then, I create the page as 

"body": {
  "storage": {
    "value": pageContent,
    "representation": "storage",
    "embeddedContent": []
  }
}

 

[1]: https://developer.atlassian.com/cloud/confluence/rest/#api-contentbody-convert-to-post

0 votes

Hi Tudor

We launched a new app that allows you to create pages from templates through Jira Workflow post-function and store the Confluence page in a Jira customfield to apply more actions like:

Workflow postfuntions

  • Update page permissions
  • Update page content
  • Update page title

Workflow conditions

  • Check if page was modified after a certain status transition
  • Check if page still has a placeholder

And so much more.

Please give it a try, I believe it would streamline alot of repeated effort on your team

Jira Confluence Workflow Extensions (JCWE) 

Give it a try I am confident you'll love it.

If you have any inquires or requests please drop me an email at admin@innovura.io

0 votes
roman Rising Star Jan 01, 2019

Hi @Tudor Munteanu,

when creating a page with REST API, you need to the storage format in the "storage" of the "body" section:

"body": {
    "view": {
      "value": "",
      "representation": "view"
    },
    "export_view": {
      "value": "",
      "representation": "view"
    },
    "styled_view": {
      "value": "",
      "representation": "view"
    },
    "storage": {
      "value": "",
      "representation": "view"
    },

I have taken this code from https://developer.atlassian.com/cloud/confluence/rest/#api-content-post. Have a look at more examples there, I think they should help.

Roman.

Hi Roman, thanks for your feedback!

I have found the answer to my concern. Before creating the page, I need to convert [1] the content to storage format.

For example, what was a <@user mention> in the Jira issue content, after the conversion it becomes

<span>&nbsp;</span><a class="user-hover" style="text-decoration: none;" title="Follow link" href="https://<your_domain>.atlassian.net/secure/ViewProfile.jspa?accountId=<accountID>"><User Display Name></a>:</p>

 

Content encapsulated in {code} ... {code} becomes encapsulated in

<pre class="code-java">...</pre>

 

[1]: https://developer.atlassian.com/cloud/confluence/rest/#api-contentbody-convert-to-post

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events