I am trying to post an attachment into the chatter feed of a bug item in GUS. Working with api version 30.0, and using the api reference for this version at: https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/quickreference_post_binary_file.htm

I am using the URL for the specific bug, and building the request body as follows (Python):

**result = requests.post(url, data=data, headers=attachment_headers)


https://<my GUS instance>/services/data/v30.0/chatter/feeds/record/a072g0000048yfwAAA/feed-items


{'Accept': 'application/json', 'Authorization': 'Bearer 00D2g0000000...ZN6tJUKiN', 'Content-Type': 'multipart/form-data...0h3VJ7mkI', 'X-PrettyPrint': '1'}


Content-Disposition: form-data; name="json"
Content-Type: application/json; charset=UTF-8;
"body": {
"messageSegments": [
{"type": "Text", "text": "Attchment from Jira CFSL project"}], 
"attachment": [
{"attachmentType": "NewFile", "title": "image-2019-07-04-16-56-15-358.png", "description": "attachment migrated from Jira"}]
Content-Disposition: form-data; name="feedItemFileUpload";
filename="image-2019-07-04-16-56-15-358.png" Content-Type: image/png 
<file content>

Getting this error:

 "errorCode" : "JSON_PARSER_ERROR",\n  "message" : "Unrecognized field \\"attachment\

Tried using capabilities instead, as specified for later versions, and getting the same error for capabilities field.

Have been googling around this a lot, would appreciate any help. Thanks, Sharon.

2 Answers 2


Was able to progress with file upload. The error on top, was that the attachment needs to be outside the body, and not be set as an array:

{ "body": { "messageSegments": [ {"type": "Text", "text": "Attchment from Jira CFSL project"}], } "attachment": {"attachmentType": "NewFile", "title": "image-2019-07-04-16-56-15-358.png", "description": "attachment migrated from Jira"} }

The next issue: It is not written anywhere, how to write contents of a binary file into the last part, . I was using this code:

with open(filepath, "rb") as img_file: my_string = base64.b64encode(img_file.read()) image_as_string = my_string.decode('utf-8') body_suffix+=image_as_string body_suffix += "\r\n"+'--'+boundary+'--'+"\r\n";

But the png file that is being uploaded cannot be opened a png. I assume it was not passes/interpreted correctly. Would appreciate an example, showing how to concatenate the image content in the request, where appear in my original question above.

Thanks, Sharon.


For anyone that may encounter this issues, it is not specified in the rest api docs, but the whole request needs to be sent in a binary format. read the file in binary format, then concatenate it with the non-binary strings after applying .encode() method on these strings.

Best regards, Sharon.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .