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.
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
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"}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted] 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried that (space before newline) and it didn't make a difference.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the "extra keys" is due to the markup parameter. In my example I am also removing it. Did you do that too?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep...the comment posted but there were no line breaks...just run on text.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@[deleted] 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."}}'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
-d '{"content":{"raw":"**Result** \n \nDeployed."}}'
New-line is created by \n##\n where # is space
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Two spaces worked for me, thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.