AnsweredAssumed Answered

Can't get batch import to work correctly (C#)

Question asked by FirstEnt Development on Oct 18, 2019
Latest reply on Oct 18, 2019 by Sanford Whiteman

Hi everyone,

I'm either getting a null response or a failure in the success field. Is there anything you can see in this C# snippet that is off or needs to be changed? Thanks in advance

 

apologies for lack of indents. copy/paste ruined it

 

static void BatchUpload(HttpClient client)
{
using (client) {
MultipartFormDataContent form = new MultipartFormDataContent();
try
{
var stream = new FileStream(@"C:\Projects\test.csv", FileMode.Open);

client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpContent content = new StringContent("");
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "test",
FileName = "test.csv"
};
content = new StreamContent(stream);
form.Add(content, "test");
//client.DefaultRequestHeaders.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.dsfdsfdsfdsfsdfkhjhjkhjk.vD056hXETFMXYxOaLZRwV7Ny1vj-tZySAWq6oybBr2w");
var address = new Uri("https://162-RCO-804.mktorest.com/rest/bulk/v1/leads.json" + $"?access_token={Models.ClientTokenInformation.Token}&format=csv");
var response = client.PostAsync(address, form).Result;
stream.Close();
var k = JsonConvert.DeserializeObject<Models.BatchResponse>(response.Content.ReadAsStringAsync().Result);
Console.WriteLine(k);
Console.ReadLine();

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();

}
}
}

Outcomes