+ Start a Discussion

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



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?






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>},

 ... }