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
Madhura KurdukarMadhura Kurdukar 

How to upload ContentVersion with REST API using curl command

I tried the curl comamnd as per Salesforce documentation but it is giving error. Could not resolve host...

The curl  command is :
curl https://xxxxxxx/services/data/v43.0/sobjects/ContentVersion -H "Authorization: Bearer token" -H "Content-Type: multipart/form-data; boundary=\"boundary_string\"" -d --data-binary @NewContentVersion.json

The NewContentVersion.json is :

{
"Title" : "Sample document",
"PathOnClient" : "CAll API.txt",
"ContentLocation" :"S",
"OwnerId":"0052Dxxxxxxx",
"VersionData":"this is the binary content of the file.Currently simple text"
}

Please let meknow what is wrong in above json or command?
Thanks
ShirishaShirisha (Salesforce Developers) 
Hi Madhura,

Greetings!

The CURL command looks good but I would suggest you to have a look at the URL which you are trying to refer:

https://trailblazers.salesforce.com/answers?id=9063A000000lRoSQAU

Example for creating a new Document via curl:

curl https://na1.salesforce.com/services/data/v23.0/sobjects/Document/ -H "Authorization: Bearer token" -H "Content-Type: multipart/form-data; boundary=\"boundary_string\"" --data-binary @newdocument.json

Example request body for creating a new Document

This code is the contents of newdocument.json. Note that the binary data for the PDF content has been omitted for brevity and replaced with “Binary data goes here.” An actual request will contain the full binary content.

--boundary_string
Content-Disposition: form-data; name="entity_document";
Content-Type: application/json

{
"Description" : "Marketing brochure for Q1 2011",
"Keywords" : "marketing,sales,update",
"FolderId" : "005D0000001GiU7",
"Name" : "Marketing Brochure Q1",
"Type" : "pdf"
}

--boundary_string
Content-Type: application/pdf
Content-Disposition: form-data; name="Body"; filename="2011Q1MktgBrochure.pdf"

Binary data goes here.

--boundary_string--


Example response body for creating a new Document

On success, the ID of the new Document is returned.

{
"id" : "015D0000000N3ZZIA0",
"errors" : [ ],
"success" : true
}

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Madhura KurdukarMadhura Kurdukar
Thanks Shirisha for you reply. However I am able to upload Document using curl command but not able to upload ContentVersion to Salesforce. My goal is to upload ContentVersion and then link the same to Cases object.