0

My Question is How we upload file as attachment while posting comment to user using chatter rest api. I have check this in Chatter rest Api Document , and i found following link https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/intro_input.htm#genericBatchExample

Still i am unable to understand that how we test this in WorkBench and PostMan.

This problem is solve by creating own rest Api using Chatter Apex. But How we do this using chatter rest api.

I am unable to understand the below code

POST /services/data/v35.0/chatter/feed-elements HTTP/1.1
Authorization: OAuth 00DRR0000000N0g!...
User-Agent: Jakarta Commons-HttpClient/3.0.1
Host: instance_name
Content-Length: 845
Content-Type: multipart/form-data; boundary=a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Accept: application/json

--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Disposition: form-data; name="json"
Content-Type: application/json; charset=UTF-8

{
   "body":{
      "messageSegments":[
         {
            "type":"Text",
            "text":"Please accept this receipt."
         }
      ]
   },
   "capabilities":{
      "content":{
         "description":"Receipt for expenses",
         "title":"receipt.pdf"
      }
   },
   "feedElementType":"FeedItem",
   "subjectId":"005RR000000DmOb"
}

--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq
Content-Disposition: form-data; name="feedElementFileUpload"; filename="receipt.pdf"
Content-Type: application/octet-stream; charset=ISO-8859-1

...contents of receipt.pdf...

--a7V4kRcFA8E79pivMuV2tukQ85cmNKeoEgJgq--

How we deploy this code Using postMan,

Please help it asap.

Thanks

0

This is not possible since v36.0 of the API:

"In version 36.0 and later, you can’t create a feed post and upload a binary file in the same request. Upload files to Salesforce first, and then use the file IDs to attach one or more files to a feed post."

https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/intro_input.htm#cc_upload_binary_files

EDIT:

I was able to perform the call you were looking for:

enter image description here

And here is the "code"

POST /services/data/v35.0/chatter/feed-elements HTTP/1.1
Host: instance.my.salesforce.com
Authorization: Bearer {your session Id}
User-Agent: PostmanRuntime/7.19.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 2f45f01c-b003-4f11-954b-3a892661d5dc,ab2ccf34-f5ec-41d2-9c0e-21c76cfc7b74
Host: instance.my.salesforce.com
Content-Type: multipart/form-data; boundary=--------------------------510963970032964458233422
Accept-Encoding: gzip, deflate
Cookie: BrowserId=tfG6nu95EemUqNWjZ_6GCg
Content-Length: 149463
Connection: keep-alive
cache-control: no-cache


Content-Disposition: form-data; name="feedElementFileUpload"; filename="/C:/Users/bander/Desktop/diff1.txt


------WebKitFormBoundary7MA4YWxkTrZu0gW--,
Content-Disposition: form-data; name="feedElementFileUpload"; filename="/C:/Users/bander/Desktop/diff1.txt


------WebKitFormBoundary7MA4YWxkTrZu0gW--
Content-Disposition: form-data; name="feedElement"

{"body":{"messageSegments":[{"type":"Text","text":"Some Text file."}]},"capabilities":{"content":{"description":"Some Text file","title":"someText.txt"}},"feedElementType":"FeedItem","subjectId":"005f4000000O242"}
------WebKitFormBoundary7MA4YWxkTrZu0gW--
  • Thanks Bryan, Its working but it work only on v35 , is it possible we will do it in latest version v47 ?. – Ashish Nigam Oct 31 '19 at 7:14
  • No, this is not possible because of the first part of my answer – Bryan Anderson Oct 31 '19 at 11:49
  • I have post new query, could you please help us to resolved it – Ashish Nigam Nov 5 '19 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.