You need to sign in to do that
Don't have an account?
Madhura 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
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
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