Make HTTP POST, PATCH, and PUT requests using inputs and learn more about uploading binary files.
Using POST, PATCH, or PUT for Input
When you make a request using the HTTP POST, PATCH, and PUT methods, you can use request parameters or a request body. The request body can contain JSON or XML. If you pass resource-specific request parameters and a request body, the request parameters are ignored. Request parameters that aren’t specific to a resource, such as parameters in a bearer token URL and the _HttpMethod parameter, are processed along with the request body. Use bearer token parameters as they are. Don’t add or remove parameters.
To submit a request using request parameters, use a Content-Type header field with the value application/x-www-form-urlencoded.
To submit a request using a request body, use one of these values in a Content-Type header field and in an Accept header field.
application/json
application/xml
Uploading Binary Files
To upload a binary file up to 2 GB (including headers), up to 75 MB for an external repository, or up to 512 MB for bulk conversations, send it as a body part in a multipart/form-data request. You can send the text of a comment (but not a post) as a JSON or XML rich input body part in the same multipart/form-data request. Alternately, you can choose to send that information in request parameters. If you pass both a rich input request body and request parameters, the request parameters are ignored.
To upload multiple binary files in the same call, see Batch Resource.
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.
Important
To create a multipart/form-data request, in the head of the request, set the Content-Type HTTP header to multipart/form-data.
For information about HTTP headers, see W3C Form content types, and RFC 2388, which defines the multipart/form-data internet media type.
This table describes the HTTP headers and parameters required in the rich input body part of a multipart/form-data request.
HTTP Headers for Rich Input Body Part
Header Value and Parameters
Description
Content-Disposition
form-data; name="json"
The request body for a post or comment. For JSON, the value of name use "json".
Content-Disposition
form-data; name="xml"
The request body for a post or comment. For XML, the value of name use "xml".
Content-Type
application/json; charset=UTF-8
The data format and character set of the request body. For JSON, the value must be application/json.
Content-Type
application/xml; charset=UTF-8
The data format and character set of the request body. For XML, the value must be application/xml.
Web browsers are typically incapable of making multipart requests when the non-binary parts, such as rich input bodies, have their own Content-Type. To work around this issue, specify a certain Content-Dispositionname and Salesforce can read the Content-Type of the rich input part. (You don’t have to specify a Content-Type for the rich input body.)
Tip
This table describes the HTTP headers and parameters required in the rich input body part of a multipart/form-data request from a web browser.
HTTP Headers for Rich Input Body Part from Web Browser
Header Value and Parameters
Description
Content-Disposition
form-data; name="feedElement"
To post a feed element with a binary file (in version 35.0 and earlier), the value of name must be "feedElement".
Content-Disposition
form-data; name="comment"
To post a comment with a binary file, the value of name must be "comment".
Content-Disposition
form-data; name="photo"
To upload an employee, user, or group photo, the value of name must be "photo".
Content-Disposition
form-data; name="file"
To upload a file to the Files home or an external repository, the value of name must be "file".
Content-Disposition
form-data; name="folderItem"
To upload a file to a folder, the value of name must be "folderItem".
Content-Disposition
form-data; name="ManagedContentInputParam"
To upload a piece of managed content, the value of name must be "ManagedContentInputParam".
Content-Disposition
form-data; name="ManagedContentVariantInputParam"
To update a managed content variant, the value of name must be "ManagedContentVariantInputParam".
This table describes the HTTP headers and parameters required in the binary upload body part of a multipart/form-data request.
Note: Specify a filename parameter and value. However, Salesforce uses the value of the title property of the File Input or the metadata of the Files Connect Item Input as the file name, not the value of the filename parameter.
Content-Disposition
form-data; name="audioFileData" filename={string}
To upload an audio file, the value of name must be "audioFileData". If you specify this value, don’t specify recordingURL or name or the request will fail.
The media type and character set of the binary file.
Spacing and carriage returns and line feeds (CRLF) are important. For example, this line requires spaces: Content-Disposition: form-data; name="feedItemFileUpload"; title="2012_q1_review.ppt". If you used CRLF instead of spaces, you would receive an error.
Note
Post a feed element with a binary file (version 35.0 and earlier)
This example uses the /chatter/feed-elements resource to post a new feed item (which is a type of feed element), upload a binary file, and attach it to the new feed item. This example uses cURL.
This example uses the /chatter/feed-elements/batch resource to post a batch of feed elements, upload two binary files, and attach them to the feed elements in the batch. Include the information about the binary parts in the request body. This example uses cURL.
1curl -H "X-PrettyPrint: 1" -F 'json={"inputs":[{"binaryPartNames":["bin1"], "richInput":{"subjectId":"me","body":{2"messageSegments":[{"type":"Text","text":"Please accept this receipt"}]},"capabilities": {"content" : {"description": "Receipt for expenses", "title":"receipt.pdf"}},"feedElementType":"FeedItem"}},3{"binaryPartNames":["bin2"],"richInput":{"subjectId":"me","body":{"messageSegments":[{"type":"Text","text":"Post Number 2"}]},4"capabilities": {"content" : {"description": "Receipt for expenses", "title":"receipt2.pdf"}},"feedElementType":"FeedItem"}}]};type=application/json'5-F "bin1=@/Users/jsmith/Desktop/receipt.pdf;type=application/octet-stream" -F "bin2=@/Users/jsmith/Desktop/receipt2.pdf;type=application/octet-stream"6-X POST https://{instanceName}/services/data/v35.0/chatter/feed-elements/batch7-H 'Authorization: OAuth 00DD00000007HoR44QATPNzhzYEJBfU' --insecure
Here is the same example formatted to show the request body parts.
This example is a generic batch request to /connect/batch that contains two subrequests. Each subrequest comments on a feed item and uploads a binary file to the comment.
Include the request body of each subrequest in the richInput properties.
Also include information about the binary parts in the binaryPartName and binaryPartNameAlias properties.
Here is the cURL example.
1curl -H "X-PrettyPrint: 1" -F 'json={ "haltOnError":true, "batchRequests":[ { "url":"/v33.0/chatter/feed-elements/0D5D0000000YG0N/capabilities/comments/items",2"method":"Post", "binaryPartName":"binaryPart1", "binaryPartNameAlias":"feedElementFileUpload", "richInput":{ "body":{ "messageSegments":[ { "type":"Text", "text":"Check out this file, it may help." } ] },3 "capabilities":{ "content":{ "title":"Presentation1.txt" } } } }, { "url":"/v33.0/chatter/feed-elements/0D5D0000000YG0M/capabilities/comments/items",4"method":"Post", "binaryPartName":"binaryPart2", "binaryPartNameAlias":"feedElementFileUpload", "richInput":{ "body":{ "messageSegments":[ { "type":"Text", "text":"Check out this file, it may help." } ] },5 "capabilities":{ "content":{ "title":"Presentation2.txt" } } } } ] };type=application/json' -F "binaryPart1=@/Users/jbleyle/Desktop/Presentation1.txt;type=application/octet-stream"6-F "binaryPart2=@/Users/jbleyle/Desktop/Presentation2.txt;type=application/octet-stream"7-X POST https://{instanceName}/services/data/v67.0/connect/batch8-H 'Authorization: OAuth 00DD00000007HoR!...' --insecure
Here is the multipart/form-data request body.
1https://{instanceName}/services/data/v67.0/connect/batch23Authorization: OAuth 00DD0000000Jhd2!...4Accept: application/json5Host: {instanceName}6Content-Type: multipart/form-data; boundary=12312378--1231239Content-Disposition: form-data; name="json"10Content-Type: application/json1112{13 "haltOnError":true,14 "batchRequests":[15 {16 "url":"/v67.0/chatter/feed-elements/0D5D0000000YG0D/capabilities/comments/items",17 "method":"Post",18 "binaryPartName":"binaryPart1",19 "binaryPartNameAlias":"feedElementFileUpload",20 "richInput":{21 "body":{22 "messageSegments":[23 {24 "type":"Text",25 "text":"Check out this file, it may help."26 }27 ]28 },29 "capabilities":{30 "content":{31 "title":"Presentation1.txt"32 }33 }34 }35 },36 {37 "url":"/v67.0/chatter/feed-elements/0D5D0000000YG0H/capabilities/comments/items",38 "method":"Post",39 "binaryPartName":"binaryPart2",40 "binaryPartNameAlias":"feedElementFileUpload",41 "richInput":{42 "body":{43 "messageSegments":[44 {45 "type":"Text",46 "text":"Check out this file, it may help."47 }48 ]49 },50 "capabilities":{51 "content":{52 "title":"Presentation2.txt"53 }54 }55 }56 }57 ]58}596061--12312362Content-Disposition: form-data; name="binaryPart1"; filename="Presentation1.txt"63Content-Type: application/octet-stream; charset=ISO-8859-164Content-Transfer-Encoding: binary6566This is the content of file 167--12312368Content-Disposition: form-data; name="binaryPart2"; filename="Presentation2.txt"69Content-Type: application/octet-stream; charset=ISO-8859-170Content-Transfer-Encoding: binary7172This is the content of file 273--123123--
Upload and crop a user photo
This example uses the /connect/user-profiles/{userId}/photo resource to upload a user profile photo and crop it using cURL.
This example uses the /connect/cms/contents resource to upload a piece of managed content. This resource is available only for enhanced CMS workspaces.
This example uses the /connect/cms/contents/variants/{variantId} resource to update a managed content variant. This resource is available only for enhanced CMS workspaces.