I have a colleague who can successfully complete a multipart post of a CSV file with a Python implementation. Using the following C# code, I am able to produce the same request body as he does, but I still receive the "Unable to parse the request body as multipart form-data" error: using (MultipartFormDataContent form = new MultipartFormDataContent())
{
StringContent listIdContent = new StringContent(VendorListId);
listIdContent.Headers.Remove("Content-Type");
form.Add(listIdContent, "\"list_ids\"");
StringContent fileNameContent = new StringContent(fileName);
fileNameContent.Headers.Remove("Content-Type");
form.Add(fileNameContent, "\"file\"");
StreamContent streamContent = new StreamContent(System.IO.File.OpenRead(filePath));
ByteArrayContent fileContent = new ByteArrayContent(streamContent.ReadAsByteArrayAsync().Result);
fileContent.Headers.Remove("Content-Type");
fileContent.Headers.Add("Content-Disposition", string.Format("form-data; name=\"data\"; filename=\"{0}\"", fileName));
form.Add(fileContent, "data", fileName);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
request.Content = form;
response = await client.SendAsync(request);
responseJson = response.Content.ReadAsStringAsync().Result;
} Here is my request: Method: POST, RequestUri: 'https://api.cc.email/v3/activities/contacts_file_import', Version: 1.1, Content: System.Net.Http.MultipartFormDataContent, Headers:
{
Authorization: Bearer (followed by my access token)
Content-Type: multipart/form-data; boundary="30473545-6c5e-44ff-8068-6dc192dc5241"
Content-Length: 473
} Here is my request body: --30473545-6c5e-44ff-8068-6dc192dc5241
Content-Disposition: form-data; name="list_ids"
3b1f9b40-8e75-11ec-a8dc-fa163e5bc304
--30473545-6c5e-44ff-8068-6dc192dc5241
Content-Disposition: form-data; name="file"
example.csv
--30473545-6c5e-44ff-8068-6dc192dc5241
Content-Disposition: form-data; name="data"; filename="example.csv"
email,company_name
ddipper@example.com,Test Company
jacksbbq@example.com,Test Company
--30473545-6c5e-44ff-8068-6dc192dc5241--
... View more