Create pages via the REST API as creating manually
Asked by Tudor Munteanu:

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](https://www.google.com/ "Follow link")  
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](https://bigfinite.atlassian.net/secure/thumbnail/20585/bullet_cat.jpg?default=false)](https://bigfinite.atlassian.net/secure/attachment/20585/20585_bullet_cat.jpg "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 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](https://www.google.com/)  
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* :  
![](https://bigfinite.atlassian.net/wiki/plugins/servlet/confluence/placeholder/unknown-attachment?locale=en_GB&version=2 "bullet_cat.jpg")

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

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


Answers:
author: Tudor Munteanu
body: 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>


author: Najjar _Innovura_
body: 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)](https://marketplace.atlassian.com/apps/1221971/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](mailto:admin@innovura.io)


author: roman
body: Hi [@Tudor Munteanu](/t5/user/viewprofilepage/user-id/2047214),

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.

comments: author: Tudor Munteanu
body: 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>


Tags: atl-adm

confluence-cloud

rest-api