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

JIRA REST API - adding a comment with newline character(s)

A B Jan 02, 2013

Following the example on [https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Add+Comment], I cannot add a comment contailing a \n newline character. I always receive

POST http://10.28.37.16:8080/rest/api/2/issue/DEMO-12/comment returned a response status of 400 Bad Request

when attempting to add the comment either using the first or secont approach.

Removing newlines from a larger comment makes it significantly illegible - therefore my question - why is that happening?

Many thanks for any suggestions or ideas!

4 answers

1 accepted

5 votes
Answer accepted
Nitram Jan 02, 2013

Hi,

Try adding one more \ before \n to make \n escape, It worked for me, I added a slash before \n and executed.

Hope this helps.

A B Jan 02, 2013

Hi Nitram!

(1) the <br> does not work as it essentially gets excaped,

(2) the \\ (I've seen also \\\\ in one post) does not work either,

but finally

(3) escaping the \n by \\\\n (four slashes; in Java) DOES WORK!!!! :)

comment.replaceAll("\n", "\\\\n")

Many thanks for your insight!

(hope this thread becomes easily googleable for those having the same problem).

2 votes
Nitram Jan 02, 2013

Hi,

Try the following,

check whether your comment's renderer is wiki style renderer, If so try adding '\\' instead '\n', '\\' is used for line break in comments(when wiki style renderer is enabled).

Try this, may work but I dono, and I have not tried,

1) Try using <br> tags, or

2) Try encoding the new line char.

The above two suggestions may or may not work.

Hope this helps.

Nitram Jan 02, 2013

Both the suggestions doesn,t work for me, adding \\ too doesn't work for me.

0 votes

PERL Code below worked

$update_comment =~ s/\n/\\n/g;

Just added one '\' in front of '\n' making it '\\n' worked.

Muddassir Farooq Mar 13, 2018

not working with curl in bitbucket api for commit build status

Jared Knipp May 09, 2018 • edited

@Muddassir Farooq Using `\\\\n` works with curl.

0 votes
Miles Gray Buckton Jan 09, 2019

What worked for me is to replace the \r\n with \n.

i.e. 

issue.Description = description.Replace("\r\n""\n");

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

958 views 12 15
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