0

So I recently completed trailheads API trail and for practice, I am trying to insert Product using bulk API

For Creating Job, I've sent following json as the request body

{
  "operation" : "insert",
  "object" : "Product2",
  "contentType" : "CSV",
  "lineEnding" : "CRLF"
}

and the response is normal

{
    "id": "7507F000003JA2OQAW",
    "operation": "insert",
    "object": "Product2",
    "createdById": "0057F000002Ez4KQAS",
    "createdDate": "2018-03-29T09:07:35.000+0000",
    "systemModstamp": "2018-03-29T09:07:35.000+0000",
    "state": "Open",
    "concurrencyMode": "Parallel",
    "contentType": "CSV",
    "apiVersion": 41,
    "contentUrl": "services/data/v41.0/jobs/ingest/7507F000003JA2OQAW/batches",
    "lineEnding": "CRLF",
    "columnDelimiter": "COMMA"
}

Now I'm trying to put the text/csv in body. I've set Content-Type to text/csv and passing following(with proper endpoint and id)

ProductCode,Family,StockKeepingUnit,Name,DisplayUrl,Description
1022,simple,123-cbc,testproduct,test.html,this is test product

(I've tried passing all values in double quotes too but it gives me same error)

The response is still normal even if I use PATCH method and send following for changing state(with proper endpoint and id)

{
   "state" : "UploadComplete"
}

But If I request for GET method for that job using ID I get

{
    "id": "7507F000003JA4KQAW",
    "operation": "insert",
    "object": "Product2",
    "createdById": "0057F000002Ez4KQAS",
    "createdDate": "2018-03-29T09:12:53.000+0000",
    "systemModstamp": "2018-03-29T09:14:16.000+0000",
    "state": "Failed",
    "concurrencyMode": "Parallel",
    "contentType": "CSV",
    "apiVersion": 41,
    "jobType": "V2Ingest",
    "lineEnding": "CRLF",
    "columnDelimiter": "COMMA",
    "numberRecordsProcessed": 0,
    "numberRecordsFailed": 0,
    "retries": 0,
    "totalProcessingTime": 0,
    "apiActiveProcessingTime": 0,
    "apexProcessingTime": 0,
    "errorMessage": "null:ClientInputError : LineEnding is invalid on user data. Current LineEnding setting is CRLF"
}
  • 2
    Are you sending the job from a Mac or Linux machine? Have you used an editor to ensure the file is saved with CRLF line endings? – David Reed Mar 29 '18 at 12:08
  • Hi, Thanks for the reply, I'm using Fedora 26 right now and I was sending the request from postman, so is it postman issue? I will validate just a min via vscode. – Indrajeet Latthe Mar 29 '18 at 13:06
  • @DavidReed Thank you very much, I pasted my body in vscode and it showed me LF so I changed to LF while creating job and it solved problem. I've one question though, so workbench do CRLF automatically? if I've do use CRLF what changes I've to do? – Indrajeet Latthe Mar 29 '18 at 13:11
  • I do not know what Workbench's standard behavior is. It is an open-source application, however, so you should be able to look if you need to. – David Reed Mar 29 '18 at 13:33
2

The error message is pointing to the issue: you've declared to Salesforce that you're sending data where lines are delimited using CRLF (the standard on Windows), but your data doesn't conform to that standard.

Mac and Linux machines, and many programmer-oriented tools and IDEs on all platforms, default to using LF only. (Classic Mac OS machines used CR only, which is now rare). Code checked out from version control may or may not be converted to your machine's preferred line ending, depending on VCS configuration.

Most IDEs and programmers' editors, and some spreadsheet applications, allow you to select your desired line endings when you save a file. Make sure that your file is saved with Windows or CRLF line endings to resolve the error.

2

change the Request body of Job Creation as follows.

{
  "operation" : "insert",
  "object" : "Product2",
  "contentType" : "CSV",
  "lineEnding" : "LF"
}

It worked for me.Also ensure that the delimiter of your CSV file is only comma.You must include all required fields when you create a record. You can optionally include any other field for the object.Files must be in UTF-8 format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.