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
kevinwukevinwu 

How do I attach an existing file to a Chatter post via the Chatter REST API?

Hello,

 

I would like to create a Chatter post via the Chatter REST API and include an existing file. To do this in APEX all you need to do is set the relatedRecordId field but I don't see how we can do this with Chatter REST.

 

I tried posting with attachment and an id but it doesn't work. Does anybody know what JSON needs to be included to include a file?

 

Thanks!

 

Kevin

ChrisOctagonChrisOctagon

Provide the "attachment" value as the JSON serialization of the "Attachment Input: Existing Content" input payload, as doc'd here: http://www.salesforce.com/us/developer/docs/chatterapi/Content/connect_resources_input.htm#cc_attach_existing_content

 

In JSON it should look like this:

 

{body: { ... body stuff },

 attachment: { contentDocumentId: <enter id here>},

 ... }