function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Unable to post multi line comment on Chatter FeedItem using Chatter REST API using Apex

I am trying to post a simple text comment to FeedItem. The comment has line breaks.

Following is my code:
String comment = 'Test1\r\n\r\nTest2';

String access_token = AuthController.getJIRAOAuthToken();

String authVal = 'OAuth '+access_token;
HttpRequest req = new HttpRequest();
String endpoint = system.label.JIRA_OAuth_SFDC_REST_API_Endpoint+'/services/data/v35.0/chatter/feed-elements/';

req.setHeader('Content-Type','application/json; charset=UTF-8');

req.setHeader('Authorization', authVal);


Http http = new Http();
HTTPResponse res = http.send(req);

I am getting below response.
System.HttpResponse[Status=Bad Request, StatusCode=400]

If I am trying the same code without "\r\n" then it works perfectly fine. Any suggestions please ?

I tried replacing "\r\n" with " " as per the rich text feed item but even that didn't help. The comment is posted along with " " in text.
Arun KumarArun Kumar

Make a Json string like below
             "text" : "First line of text.",
             "type" : "Text"
            "text" : "Second line of text.",
            "type" : "Text"
Please let me know if the helps.

As a common practice, if your question is answered, please choose 1 best answer.
Additionaly you can give every answer a thumb up if that answer is helpful to you.