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

FirstEnt_Develo
Level 2

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

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();

}
}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (2)
1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Can't get batch import to work correctly

Rather than providing code in a specific language, can you please provide the actual HTTP payload you’re sending to the server (i.e. send to a mock server)? That’s what really matters.