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

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

Multiline comment on pull request via API 2.0

I am trying to post a comment that includes newlines to a pull request using https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/comments 

 

My request body looks like this: 

{"content":{"raw":"Report\nTotal Files Examined: 20\nLooks Good!"}}

I would expect the UI comment to look like this:

Report
Total Files Examined: 20
Looks Good!

The request is accepted, but the output in the pull request looks like this:

Report Total Files Examined: 20 Looks Good!

If I open the HTML of the PR page, I see the following:

<p>Report
Total Files Examined: 20
Looks Good!</p>

I believe what is happening is that the raw content is always being pasted into the <p> tags, but what *should* happen is every newline is converted into a new <p> tag. 

 

I have also tried using \\n and <br>, \\n turns into this in the UI

Report\nTotal Files Examined: 20\nLooks Good!

and <br> turns into this:

Report<br>Total Files Examined: 20<br>Looks Good!

 

Is there any way around this? I need to UI to respect the line breaks somehow.

1 answer

1 accepted

0 votes
Answer accepted

I discovered I can send using markdown and am using " \n" (space and newline) to make line breaks, this creates the multilines as I want.

###Report \nTotal Files Examined: 20 \nLooks Good!

 becomes

REPORT

Total Files Examined: 20
Looks Good!

How did you get this to work? I'm trying to send markdown and it's not working. I tried specifying that it is markup and this results in an error:

 

test.sh "This is a test\nthis is only a test\n\`here is some code\`"

{"content":{"raw":"This is a test\nthis is only a test\n`here is some code`","markup":"markdown"}}

{"type": "error", "error": {"fields": {"content.markup": "extra keys not allowed"}, "message": "Bad request"}}

@Charles Hudak The API docs seem to be incorrect (though they're correct for the UI API).

 

I sent as raw without a markup parameter and as I said above with a space character before the newline.

 

So in your case: 

{"content":{"raw":"This is a test\nthis is only a test\n`here is some code`","markup":"markdown"}}

becomes

{"content":{"raw":"This is a test \nthis is only a test \n`here is some code`"}}

 

That should work

I tried that (space before newline) and it didn't make a difference.

the "extra keys" is due to the markup parameter. In my example I am also removing it. Did you do that too?

Yep...the comment posted but there were no line breaks...just run on text.

@Charles Hudak any luck with that multiline text? I've tried without success, I do send text as markup and it's rendered as markup but no line breaks (API 2.0).

-d '{"content":{"raw":"**Result** \nDeployed."}}'

-d '{"content":{"raw":"**Result** \n  \nDeployed."}}'

New-line is created by \n##\n where # is space

Like Anton Plebanovich likes this

Two spaces worked for me, thanks!

Suggest an answer

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

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

239 views 4 9
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