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

How to send tags (storage format) via REST API?

Edwin B December 17, 2018

Using the REST API documentation, I'm attempting to create a template with some custom formatting.  However, any tags I include are added as string literals, instead of being used as a tag.

A very simple example: I created a new (space) template manually via the UI.  Getting this template from the REST API, I can see the following body data:

  "body": {
    "storage": {
      "value": "<at:declarations /><p>Some body content here.</p>",
      "representation": "storage"
    }
  },

I delete said template and attempt to create the template again via a curl call;  using the documentation.

curl -k --request POST \ --url 'https://myurl' \
--user '[REMOVED]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
  "name": "My Awesome Template",
  "templateType": "page",
  "body": {
    "storage": {
        "value": "<at:declarations /><p>Some body content here.<p>",
        "representation": "storage"
      }
  },
  "description": "Some Description",
  "space": {
    "key": "someKey"
  }
}'

The call returns successfully and a template is created.  However, the contents are just the literal string value: "<at:declarations /><p>Some body content here.<p>".  Attempting to use escape sequences (&'s) results in the same thing.  What am I missing?

1 answer

0 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 21, 2018

Hello Edwin and welcome to the Community,

You have a very solid understanding of template and accessing the API for Confluence. I went through your example code and tested on Confluence Server 6.13. I did find a minor issue which may be causing your problem.

When creating the page, I found that your storage format was not closed properly. Here is what you storage value should look like:

"value": "<at:declarations /><p>Some body content here.</p>",

Here is the entire example call I used:

 curl -k --request POST \ --url 'http://confluence.server.com/rest/api/content' \
--user 'user:password' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"name": "My Awesome Template",
"title": "Template",
"type": "page",
"templateType": "page",
"space":{
"key":"TEST"
},
"body": {
"storage": {
"value": "<at:declarations /><p>Some body content here.</p>",
"representation": "storage"
}
},
"description": "Some Description"
}'

image.png

Please give your CURL call a try again with the value correction and let us know the results. I did confirm on my end it created a page with content (as seen from the screenshot above).

Regards,
Stephen Sifers

Edwin B January 2, 2019

Unfortunately, closing the paragraph tag did not change the result on my end.  I suspect this problem is due to an issue with the version of Confluence I am using (not 6.13), and that you would have not seen string literals on your server even if you had not closed this tag

I have been able to find a workaround by first creating a template and then updating it with the storage format data I want.  I certainly don't like, but it works.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events