The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

API - Add a new comment to a Card - how to use line breaks in text?

Beurswand
October 11, 2024

I try to add a comment with multiple lines via the api: 

 

curl --request POST \ --url 'https://api.trello.com/1/cards/{id}/actions/comments?text={text}

I tried the following values for {text} , without success:

Line 1 <br /> Line 2

Line 1 %0A Line 2

Line 1 (space) Line 2

Line 1\ Line 2

Line 1 \xA Line 2

Line 1 \n Line 2

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Deleted user
October 11, 2024

Hallo @Beurswand 

You use the URL-encoded newline character, %0A if you are declaring the value of the text parameter in the request path.

If that's not working, then you haven't properly declared the Content-Type header as being application/json

Beurswand
October 11, 2024

Thanks for your reply David,

So I tried it again:

"text": "Line 1%0ALine 2"

Result
Trello_Comment.png

Deleted user
October 11, 2024

"text": "Line 1%0ALine 2" is JSON, not plain text.

If you're going to use cURL's --data parameter and declare the value of text parameter in the request body using JSON instead of using plain text and as a request path parameter, as you've shown in your original question, then the \n character is used:

{
"text": "Line 1\nLine 2\nLine3"
}

Broadly speaking, when doing PUT and POST requests, it really is best practice to declare ALL parameters, including the key and token parameters, in the request body, not as path parameters:

Untitled.png

...which in the UI would be rendered to the user as:

Untitled2.png

 

The reason for declaring ALL parameters in the request body for PUT and POST requests is consistency. Many other REST APIs from other products enforce that method, plus many types of parameters, such as nested arrays, have no equivalent in plain text, so they cannot be expressed when declared in the request path.

Beurswand
October 11, 2024

Thx, this with \n is working.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events