Problem resolved!
{
"operation": "insert",
"createdDate": "2019-03-28T19:40:38.000+0000",
"systemModstamp": "2019-03-28T19:41:34.000+0000",
"state": "JobComplete",
"concurrencyMode": "Parallel",
"contentType": "CSV",
"apiVersion": 45.0,
"jobType": "V2Ingest",
"lineEnding": "CRLF",
"columnDelimiter": "COMMA",
"numberRecordsProcessed": 883,
"numberRecordsFailed": 809,
"retries": 0,
"totalProcessingTime": 11210,
"apiActiveProcessingTime": 10847,
"apexProcessingTime": 0
}
Just in case anyone else runs into this same issue. I didn't find this information anywhere, I just kept modifying the code until I got it working. The issue for me was how the CSV file was being uploaded to Salesforce.
This was my original code.
MultipartFormDataContent content = new MultipartFormDataContent()
{
Headers =
{
ContentType = new MediaTypeHeaderValue("text/csv")
}
};
client.DefaultRequestHeaders.Accept.Clear();
using (FileStream fs = new FileStream(UploadFileType.FilePath, FileMode.Open, FileAccess.Read))
{
StreamContent streamContent = new StreamContent(fs);
streamContent.Headers.Add("Content-Type", "application/octet-stream");
streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + Path.GetFileName(UploadFileType.FilePath) + "\"");
content.Add(streamContent);
Task<HttpResponseMessage> responseMessage = client.PutAsync(BulkEndPoint + ContentUrl, content);
var result = responseMessage.Result.Content.ReadAsStringAsync();
string resultString = result.Result;
}
I'm guessing it didn't like the headers for the content, streamContent variables.
The new code, this still uploads the file, but doesn't fail when the job is closed. And as shown above, the return JSON from the job info no longer has an error message. This contradicts the examples I was able to find about uploading files to Salesforce using the bulk API v2.0.
// We don't want any weird headers hanging around
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("Accept", "application/json");
using (FileStream fs = new FileStream(UploadFileType.FilePath, FileMode.Open, FileAccess.Read))
{
StreamContent streamContent = new StreamContent(fs);
streamContent.Headers.Add("Content-Type", "text/csv");
//streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + Path.GetFileName(UploadFileType.FilePath) + "\"");
Task<HttpResponseMessage> responseMessage = client.PutAsync(BulkEndPoint + ContentUrl, streamContent);
var result = responseMessage.Result.Content.ReadAsStringAsync();
string resultString = result.Result;
}
Best Answer
204 No Content
does not mean an error code. It still reflects a successful operation. This is from the MDN docs:Additionally, Status Codes and Error Responses documentation lists the different status codes that are used in Salesforce REST API Contexts.
Irrespective of the context where it is used, the status code
204
is always a successful response.