[SalesForce] bulk api text/csv CRLF error

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"
}

Best Answer

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.

Related Topic