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

how do you create a confluence page with the REST API when the content has new lines

Alonzo Benavides November 15, 2016

This question is in reference to Atlassian Developer Documentation: Confluence REST API Examples

I am working on creating pages in Confluence from the command line. Specifically, I want to move an old documentation system into Confluence. I have tried to use the REST API examples, but they only work for trivially easy content (a single sentence for example).

Command line code:

curl -v -u u:p -X POST -H "Content-Type: application/json" --data-binary @Netsuite_Features.txt https://confluence/rest/api/content/ -k

Netsuite_Features.txt content:

{"type":"page","ancestors":[{"type":"page","id":99231339}],"title":"Netsuite","space":{"key":"LD"},"body":{"storage":{"value":"Back to\n\ntesting \\n double \r sasdf \\r testing \r\n again \\r\\n work please","representation":"storage"}}}

The resulting confluence page that is created:

Back to testing \n double sasdf \r testing again \r\n work please

 

You will notice that some of the new lines are swallowed and in some cases replaced with spaces. I am using --data-binary in my curl call so that the new lines would be preserved (https://confluence.atlassian.com/jirakb/objects-sent-to-jira-via-curl-in-json-format-have-line-breaks-stripped-321857070.html

 

I have been stuck on this for a long time. I have tried a lot of things:

  • replacing all LF with CRLF and then having curl replace them with --crlf
  • all forms of escaping LF and CR and CRLF
  • --data instead of --data-binary
  • more things

Can anyone help me? I am completely blocked and I have 2500 files to move into confluence.

Extra detail:

  • i am using a windows 8, curl 7.30.0
  • Confluence 5.10.7

 

 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Alonzo Benavides November 21, 2016

I never got this working. Instead I scraped the wiki pages I wanted and exported them as HTML and then I did an Import through the Content Tools section of Confluence.

0 votes
Panos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 16, 2016

Seems curl is not your friend, have you tried the confluence-cli tools? Although the examples page is not working, i am pretty sure you can find your way by looking the how to's and there is an addPage command that should fit your needs

 

addPage - Add a new page.

	 Required parameters: space, title, content or file

	 Optional parameters: parent, labels, replace, content2, findReplace, findReplaceRegex, noConvert, markdown, encoding
Alonzo Benavides November 16, 2016

I have not tried confluence CLI, but it is worth a shot. I am not sure the problem is with Curl. The Atlassian docs even use curl in the examples; I think it is the API itself swallowing these characters.

Panos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 16, 2016

CLI is deffo worth to check. Using --data-binary curl should send new lines, but if you suspect that you are writing something wrong, then you can use the REST browser to check the API.

TAGS
AUG Leaders

Atlassian Community Events