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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,632
Community Members
 
Community Events
185
Community Groups

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

1 vote
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!

Unfortunately, two spaces didn't work for me but \n\r works:

curl --request POST --header 'Content-Type:application/json' -d '{"content":{"raw": "line 1\n\rline 2"}}' https://api.bitbucket.org/2.0/repositories/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pullrequests/$BITBUCKET_PR_ID/comments?access_token=$ACCESS_TOKEN

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events