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

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

Remco Kragt _exposure_ 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

1 vote
Answer accepted
David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2024 edited

Hallo @Remco Kragt _exposure_ 

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

Remco Kragt _exposure_ October 11, 2024

Thanks for your reply David,

So I tried it again:

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

Result
Trello_Comment.png

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2024 edited

"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.

Remco Kragt _exposure_ October 11, 2024 edited

Thx, this with \n is working.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Upcoming Trello Events