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
Muni ChittetiMuni Chitteti 

REST pi Inserting a New Document getting error as "Premature end of input"

Hi All,

I am trying to insert a new document into the Salesforce system referring https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_insert_update_blob.htm.

Getting the below error 
[
    {
        "message": "Premature end of input.",
        "errorCode": "JSON_PARSER_ERROR"
    }
]

Input

 
curl -X POST \
  https://company.cs15.my.salesforce.com/services/data/v41.0/sobjects/Document/ \
  -H 'Authorization: OAuth 00De000000........' \
  -H 'Content-Type: multipart/form-data; boundary=boundary_string' \
  -H 'Postman-Token: 0ce6bc42-75a3-45b2-b4d1-03cae18be8b4' \
  -H 'cache-control: no-cache' \
  -d '--boundary_string
Content-Disposition: form-data; name="entity_document";
Content-Type: application/json
{  
    "Description" : "Marketing brochure for Q1 2011",
    "Keywords" : "marketing,sales,update",
    "FolderId" : "00l39000001uYvs",
    "Name" : "Marketing Brochure Q1",
    "Type" : "pdf"
}

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

JVBERi0xLjcKCjQgMCBvYmoKPDwKL0ZpbHRlciAvRmxhdGVEZWNvZGUKL0xlbmd0aCA1
NjgKPj4Kc3RyZWFtCnicdVU7jt0wDOx9CtcBRIikfjzGVjnAAkmKvADJ/YsMLUuyn5Ot
tEOLGg4.........iAwIFIKL1Jvb3QgMSAwIFIKL1NpemUgNwo+PgpzdGFy
dHhyZWYKMTEyNgolJUVPRgo=
 
--boundary_string--'

Postman service Image
 
Best Answer chosen by Muni Chitteti
Santosh Reddy MaddhuriSantosh Reddy Maddhuri
Hi Muni,

Try this changes.

 
curl -X POST \
  https://company.cs15.my.salesforce.com/services/data/v41.0/sobjects/Document/ \
  -H 'Authorization: OAuth 00De000000........' \
  -H 'Content-Type: multipart/form-data; boundary=\'boundary_string\' ' \
  -H 'Postman-Token: 0ce6bc42-75a3-45b2-b4d1-03cae18be8b4' \
  -H 'cache-control: no-cache' \
  -d  '@newdocument.json'


--boundary_string
Content-Disposition: form-data; name="entity_document";
Content-Type: application/json
{  
    "Description" : "Marketing brochure for Q1 2011",
    "Keywords" : "marketing,sales,update",
    "FolderId" : "00l39000001uYvs",
    "Name" : "Marketing Brochure Q1",
    "Type" : "pdf"
}

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

JVBERi0xLjcKCjQgMCBvYmoKPDwKL0ZpbHRlciAvRmxhdGVEZWNvZGUKL0xlbmd0aCA1
NjgKPj4Kc3RyZWFtCnicdVU7jt0wDOx9CtcBRIikfjzGVjnAAkmKvADJ/YsMLUuyn5Ot
tEOLGg4.........iAwIFIKL1Jvb3QgMSAwIFIKL1NpemUgNwo+PgpzdGFy
dHhyZWYKMTEyNgolJUVPRgo=
 
--boundary_string--


Please mark this as a best answer if its helps. So others can benefit.


Regards,
Santosh.