Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

Confluence Bingo Round 3!

That’s right! Grandma’s back at it again, and this time she’s brought all her friends. In honor of Team '21, this Bingo round is dedicated to all things team-related, and the prizes are no exception....

2,922 views 31 22
Read article

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